代码
1 #include<iostream>
2 #include<algorithm>
3 using namespace std;
4
5 int ISYEAP(int x){
6 if((x%100!=0 && x % 4 == 0) || (x % 400 == 0) )return 1;
7 else return 0;
8 }
9 int dayOfMonth[13][2] = {
10 0,0,
11 31,31,
12 28,29,
13 31,31,
14 30,30,
15 31,31,
16 30,30,
17 31,31,
18 31,31,
19 30,30,
20 31,31,
21 30,30,
22 31,31
23 };
24 typedef struct Date{
25 int Day;
26 int Month;
27 int Year;
28 void nextDay(){
29 Day++;
30 if(Day > dayOfMonth[Month][ISYEAP(Year)]){
31 Day = 1;
32 Month++;
33 if(Month > 12){
34 Month = 1;
35 Year++;
36 }
37 }
38 }
39 }Date;
40
41 int buf[3001][13][32];
42 int main(){
43 Date tmp;
44 tmp.Year = 0,tmp.Month = 1,tmp.Day = 1;
45 int cnt = 0;
46 while(tmp.Year != 3001){
47 buf[tmp.Year][tmp.Month][tmp.Day] = cnt;
48 tmp.nextDay();
49 cnt++;
50 }
51 int y,m,d;
52 while(scanf("%d%d%d",&y,&m,&d) != EOF){
53 int days = abs(buf[y][m][d] - buf[y][1][1]) + 1; //算和今年元旦的差值
54 printf("%d
",days);
55 }
56 return 0;
57 }