#include <iostream> using namespace std; //计算当年月和日的天数 int GetMonthDay(int year, int month, int day) { int GetMonthday[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365}; int monthday = GetMonthday[month - 1] + day; if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) && month > 2) { return ++monthday; } return monthday; } //判断闰年否,返回当年的天数 int GetYearDay(int year) { int GetYearday[2] = {365,366}; if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return GetYearday[1]; } return GetYearday[0]; } int main() { int y1,m1,d1,y2,m2,d2; int minyear,maxyear; int count,n1,n2; while(scanf("%04d%02d%02d %04d%02d%02d",&y1,&m1,&d1,&y2,&m2,&d2) != EOF) { count = 0; //找到小的年,按年相加直到加到与比较年同年 minyear = y1 < y2 ? y1 : y2; maxyear = y1 > y2 ? y1 : y2; //此时不能等于maxyear,如果等于则多加了一年的天数 while(minyear < maxyear) { count += GetYearDay(minyear); ++minyear; } //调用计算当年月和日天数的函数,此时拿到两个同年的月和日的天数: n1 = GetMonthDay(y1,m1,d1); n2 = GetMonthDay(y2,m2,d2); //这一步需要得出Max(n1,n2) - Min(n1,n2)的天数 //最后,把两个日期的年的相差天数+Max(n1,n2) - Min(n1,n2)的天数+1就得出两个日期相差的天数了 int max = n1 > n2 ? n1 : n2; int min = n1 < n2 ? n1 : n2; cout << count + (max - min)+1 << endl; } return 0; }