日期计算。NYOJ75
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=75
我在学习DEV 的调试,就拿来这个练手了。但是没有达到预期效果。
#include<stdio.h>
int ruinian(int year)
{
if(year%400==0||(year%4==0&&year%100!=0))
return 1;
else return 0;
}
int main()
{
int n,year,i,date,sum=0,month;
scanf("%d",&n);
while(n--)
{
sum=0;
scanf("%d%d%d",&year,&i,&date);
for(month=1;month<i;month++)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
sum=sum+31;
if(month==4||month==6||month==9||month==11)
sum=sum+30;
if(month==2)
{
if(ruinian(year))
sum=sum+29;
else
sum=sum+28;
}
}
sum=sum+date;
printf("%d\n",sum);
}
return 0;
}
浙公网安备 33010602011771号