请看注释部分!谢谢!
#include <iostream>
#define isleap(x) x%100!=0 && x%4==0 || x%400==0
using namespace std;
int dayofmonth[13][2] = {
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31
};
int abs(int x){
return x>0?x:-x;
}
int main(){
int buf[5001][13][32]; //这行写在main里面运行就超时,放在main()外面就运行正常
int y=0,m=1,d=1,gap=0;
while(y!=5000){
buf[y][m][d] = gap++;
d++;
if(d>dayofmonth[m][isleap(y)]){
d=1;
m++;
if(m>12){
m=1;
y++;
}
}
}
int y1,y2,m1,m2,d1,d2;
while(scanf("%4d%2d%2d",&y1,&m1,&d1)!=EOF){
scanf("%4d%2d%2d",&y2,&m2,&d2);
int t =buf[y1][m1][d1]-buf[y2][m2][d2];
printf("%d\n",abs(t));
}
return 0;
}