文章
8
粉丝
216
获赞
20
访问
67.2k
#include<bits/stdc++.h>
using namespace std;
int tab[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
bool LeapYear(int year){
return ( (!(year%4) && year%100) || !(year%400) );
}
//计算这两个日期分别与0000.00.00的日期差值再作差
int ManyDays(int year, int month, int day){
int sum = 0;
for(int i=0; i<year; i++){
for(int j=1; j<13; j++)
sum += tab[LeapYear(i)][j];
}
for(int i=1; i<month; i++)
sum += tab[LeapYear(year)][i];
sum += day;
return sum;
}
int main(){
int year1, month1, day1;
int year2, month2, day2;
while(~scanf("%4d%2d%2d",&year1, &month1, &day1)){
scanf("%4d%2d%2d",&year2, &month2, &day2);
int sum1 = ManyDays(year1, month1,day1);
int sum2 = ManyDays(year2, month2,day2);
printf("%d\n", abs(sum1-sum2)+1);//此处注意两个连续日期规定其间天数为2
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发