题目
code
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int isLeap(int year){
if(((year%4==0)&&(year%100!=0))||(year%400==0)){
return 1;
}
else return 0;
}
int main(){
int y1,y2,m1,m2,d1,d2,time1,time2;
int month[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}};
while(scanf("%d%d",&time1,&time2)!=EOF){
if(time1>time2){
int temp=time1;
time1=time2;
time2=temp;
}
y1=time1/100000;
y2=time2/100000;
m1=time1%100000/100;
m2=time2%100000/100;
d1=time1%100;
d2=time2%100;
int ans=1;
while(y1<y2||d1<d2||m1<m2){
d1++;
if(d1==month[m1][isLeap(y1)]+1){
m1++;
d1=1;
}
if(m1==13){
y1++;
m1=1;
}
ans++;
}
printf("%d\n",ans);
}
return 0;
}
总结
- if(((year%40)&&(year%100!=0))||(year%4000) 来判断闰年
- 先 if(time1>time2) 让time1 是较小的值!—》初始化
