日期题目:算两个日期之间的相差天数,程序整体没错,编译有问题
#include<stdio.h>#include<algorithm>
#include<string.h>
using namespace std;
int dayOfMonth[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
};
struct Date
{
int Day;
int Month;
int Year;
void nextDay()
{
Day ++;
if(Day>dayOfMonth[Month][ISYEAP(Year)])
{
Day=1;
Month++;
if(Month>12)
{
Month=1;
Year++;
}
}
}
};
int buf[5001][13][32];
int abs(int x)
{
return x<0?-x:x;
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
date tmp;
tmp.day=1;
tmp.month=1;
tmp.day=0;
tmp.nextday();
int cnt=0;
while(tmp.year<5001)
{
buf[year][month][day]=cnt;
tmp.nextday();
cnt++ ;
}
while(scanf("%4d%d%d",&tmp.year,&tmp.month,&tmp.day)!=EOF)
{
int a=buf[tmp.year][tmp.month][tmp.day];
scanf("%4d%d%d",&tmp.year,&tmp.month,&tmp.day);
int b=buf[tmp.year][tmp.month][tmp.day];
a=a-b+1;
a=abs(a);
printf("%d\n",a);
}
return 0;
}