第几天?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90652 Accepted Submission(s): 34083
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20
2006/3/12
Sample Output
20
71
Author
lcy
Source
C语言程序设计练习(一)
#include<stdio.h>
int main()
{
int y,m,d;
while(scanf("%d%d%d",&y,&m,&d)!=EOF)
{
if((y%4==0&&y%100!=0)||(y%400==0))
{
switch(m){
case 1:printf("%d\n",d); break;
case 2:printf("%d\n",31+d); break;
case 3:printf("%d\n",60+d);break;
case 4:printf("%d\n",91+d);break;
case 5:printf("%d\n",121+d);break;
case 6:printf("%d\n",152+d);break;
case 7:printf("%d\n",182+d);break;
case 8:printf("%d\n",213+d);break;
case 9:printf("%d\n",243+d);break;
case 10:printf("%d\n",273+d);break;
case 11:printf("%d\n",304+d);break;
case 12:printf("%d\n",334+d);break;
default:printf("error\n");
}
}
else if((y%4!=0&&y%100==0)||(y%400!=0))
{
switch(m)
{
case 1:printf("%d\n",d); break;
case 2:printf("%d\n",31+d); break;
case 3:printf("%d\n",59+d);break;
case 4:printf("%d\n",90+d);break;
case 5:printf("%d\n",120+d);break;
case 6:printf("%d\n",151+d);break;
case 7:printf("%d\n",181+d);break;
case 8:printf("%d\n",212+d);break;
case 9:printf("%d\n",242+d);break;
case 10:printf("%d\n",272+d);break;
case 11:printf("%d\n",303+d);break;
case 12:printf("%d\n",333+d);break;
default:printf("error\n");
}
}
}
}