#include <iostream>
#define N 1000
using namespace std;
int daysOfMonth(int y,int m);
int daysOfYear(int y);
int tdays(int year,int month,int day);
bool isLeapYear(int n);
typedef struct Time{
int year;
int month;
int day;
int total;
}Time;
int main()
{
Time time[2];
while(!cin.eof())
{
cin>>time[0].year>>time[0].month>>time[0].day;
cin>>time[1].year>>time[1].month>>time[1].day;
time[0].total=tdays(time[0].year,time[0].month,time[0].day);
time[1].total=tdays(time[1].year,time[1].month,time[1].day);
cout<<time[0].total-time[1].total<<endl;
}
}
int tdays(int year,int month,int day)
{
int y,m,sum=0;
for (y=N;y<year;y++)
sum+=daysOfYear(y);
for (m=1;m<month;m++)
sum+=daysOfMonth(year,m);
sum+=day-1;
return sum;
}
int daysOfMonth(int y,int m)
{
if (m==1||m==3||m==5||m==7||m==8||m==10||m==12)
return 31;
else if(m==4||m==6||m==9||m==11)
return 30;
else if(m==2)
{
if (isLeapYear(y))
return 29;
else
return 28;
}
}
int daysOfYear(int y)
{
if (isLeapYear(y))
return 366;
else
return 365;
}
bool isLeapYear(int n)
{
if (n%400==0||n%4==0&&n%100!=0)
return true;
else
return false;
}
以上是完整程序。
测试数据:1984 7 1 1980 9 10
1990 2 5 2016 1 28
输出结果:
为何在输入了Ctrl+Z之后仍然会有一行输出?