第几天?
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 ",d); break;
case 2:printf("%d ",31+d); break;
case 3:printf("%d ",60+d);break;
case 4:printf("%d ",91+d);break;
case 5:printf("%d ",121+d);break;
case 6:printf("%d ",152+d);break;
case 7:printf("%d ",182+d);break;
case 8:printf("%d ",213+d);break;
case 9:printf("%d ",243+d);break;
case 10:printf("%d ",273+d);break;
case 11:printf("%d ",304+d);break;
case 12:printf("%d ",334+d);break;
default:printf("error ");
}
}
else if((y%4!=0&&y%100==0)||(y%400!=0))
{
switch(m)
{
case 1:printf("%d ",d); break;
case 2:printf("%d ",31+d); break;
case 3:printf("%d ",59+d);break;
case 4:printf("%d ",90+d);break;
case 5:printf("%d ",120+d);break;
case 6:printf("%d ",151+d);break;
case 7:printf("%d ",181+d);break;
case 8:printf("%d ",212+d);break;
case 9:printf("%d ",242+d);break;
case 10:printf("%d ",272+d);break;
case 11:printf("%d ",303+d);break;
case 12:printf("%d ",333+d);break;
default:printf("error ");
}
}
}
}