a263.
日期差幾天
--
板橋高中練習題
| From: [123.193.67.154] |
發表日期
:
2011-12-31 01:45
我哪裡錯了@@
WA (line:13)
答案不正確您的答案為: 294796 正確答案為: 294795
#include<stdio.h>
int countday();
int monthday[]={0,31,59,90,120,151,181,212,243,273,304,334};
int year[2],month[2],day[2];
int main()
{
while(scanf("%d %d %d",&year[0],&month[0],&day[0])!=EOF)
{
scanf("%d %d %d",&year[1],&month[1],&day[1]);
printf("%d\n",countday());
}
return 0;
}
int countday()
{
int i=0,aday=0,bday=0,leap=0,time=0;
aday+=monthday[month[0]-1]+day[0];
bday+=monthday[month[1]-1]+day[1];
do{
if(time!=0)
{
year[0]-=((year[0]-year[1])>0)-((year[0]-year[1])<0);
}
else
{
time++;
}
if((year[0]%4==0 && year[0]%100!=0)||(year[0]%400==0))
{
leap++;
printf("year=%d leap=%d\n",year[0],leap);
}
aday+=365*(((year[0]-year[1])>0)-((year[0]-year[1])<0));
}while(year[0]!=year[1]);
return ((aday-bday)*(((aday-bday)>0)-((aday-bday)<0))+leap);
}