本题要求编写程序计算某年某月某日是该年中的第几天。
输入格式:
输入在一行中按照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。闰年的2月有29天。
输出格式:
在一行输出日期是该年中的第几天。
输入样例1:
2009/03/02
输出样例1:
61
输入样例2:
2000/03/02
输出样例2:
62
#include<stdio.h>
int main()
{
int a,b,c,d,e;
scanf("%d/%d/%d",&a,&b,&c);
if ((a%4==0&&a%100!=0)||a%400==0)
{
switch(b)
{
case 01:
d=0;
break;
case 02:
d=31;
break;
case 03:
d=31+29;
break;
case 04:
d=31+29+31;
break;
case 05:
d=31+29+31+30;
break;
case 06:
d=31+29+31+30+31;
break;
case 07:
d=31+29+31+30+31+30;
break;
case 8:
d=31+29+31+30+31+30+31;
break;
case 9:
d=31+29+31+30+31+30+31+31;
break;
case 10:
d=31+29+31+30+31+30+31+31+30;
break;
case 11:
d=31+29+31+30+31+30+31+31+30+31;
case 12:
d=31+29+31+30+31+30+31+31+30+31+30;
break;
}
}
else
{
switch(b)
{
case 01:
d=0;
break;
case 02:
d=31;
break;
case 03:
d=31+28;
break;
case 04:
d=31+28+31;
break;
case 05:
d=31+28+31+30;
break;
case 06:
d=31+28+31+30+31;
break;
case 07:
d=31+28+31+30+31+30;
break;
case 8:
d=31+28+31+30+31+30+31;
break;
case 9:
d=31+28+31+30+31+30+31+31;
break;
case 10:
d=31+28+31+30+31+30+31+31+30;
break;
case 11:
d=31+28+31+30+31+30+31+31+30+31;
case 12:
d=31+28+31+30+31+30+31+31+30+31+30;
break;
}
}
e=d+c;
printf("%d",e);
return 0;
}