Link:
https://www.nowcoder.com/acm/contest/115/B
Source: Niuke.com
Source: Niuke.com
Time limit: C/C++ 1 second, other languages 2 seconds
Space limit: C/C++ 32768K, other languages 65536K
64bit IO Format: %lld
Space limit: C/C++ 32768K, other languages 65536K
64bit IO Format: %lld
Topic description
Give a date of birth, for example: 1999-09-09,
ask: from the day of birth to today 2018-04-21 (including the date of birth and today), how many days, the year, month and day do not contain numbers 4?
ask: from the day of birth to today 2018-04-21 (including the date of birth and today), how many days, the year, month and day do not contain numbers 4?
Enter description:
Enter an integer T on the first line (representing the number of samples) The next group T samples One line per sample, containing a string "yyyy-mm-dd" (1990<=yyyy<=2018) Questions to ensure the correctness of the test data
Output description:
Output the number of days required by the question
Example 1
enter
1 1999-09-09
output
5020
#include<iostream> #include<cstdio> using namespace std; int a[2020][20][40]; void solve(){ int cnt=0; for(int i=1990;i<=2018;i++){ for(int j=1;j<=12;j++){ if(j==2){ if(((i%4==0)&&(i%100!=0))||(i%400==0)){ for(int k=1;k<=29;k++){ if((i%10!=4)&&(j%10!=4)&&(k%10!=4)) cnt++; a[i][j][k]=cnt; } } else{ for(int k=1;k<=28;k++){ if((i%10!=4)&&(j%10!=4)&&(k%10!=4)) cnt++; a[i][j][k]=cnt; } } } else if(j==1||j==3||j==5||j==7||j==8||j==10||j==12){ for(int k=1;k<=31;k++){ if((i%10!=4)&&(j%10!=4)&&(k%10!=4)) cnt++; a[i][j][k]=cnt; } } else if(j==2||j==4||j==6||j==9||j==11){ for(int k=1;k<=30;k++){ if((i%10!=4)&&(j%10!=4)&&(k%10!=4)) cnt++; a[i][j][k]=cnt; } } } } } int main(){ int n,x,y,z; cin>>n; solve(); while(n--){ scanf("%d-%d-%d",&x,&y,&z); int t=(a[2018][4][21]-a[x][y][z]); if((x%10!=4)&&(y%10!=4)&&(z%10!=4)) t+=1; cout<<t<<endl; } return 0; }