#include <stdbool.h> #include <stdio.h> bool learyear(int year)//判断是否闰年 { return (year%4==0&&year%100!=0||(year%400==0)); } int numyear(int year)//判断每年多少天 { if(learyear(year)) return 366; else return 365; } int main() { int year1,month1,day1,year2,month2,day2; scanf("%4d%2d%2d",&year1,&month1,&day1); scanf("%4d%2d%2d",&year2,&month2,&day2); int Days[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}}; int sum1=0,sum2=0; //计算year1的天数 for(int i=0;i<year1;i++) { sum1+=numyear(i); } for(int j=0;j<month1;j++) { sum1+=Days[learyear(year1)][j]; } sum1+=day1; //计算year2的天数 for(int i=0;i<year2;i++) { sum2+=numyear(i); } for(int j=0;j<month2;j++) { sum2+=Days[learyear(year1)][j]; } sum2+=day2; //求出差值 int num=sum2-sum1+1; if(num<0) { num=-num; } printf("%d",num); return 0; }