Problem J: 结构体:计算输入日期是该年的第几天
Description
定义一个结构体变量(包括年、月、日),输入一个日期,计算并输出该日是本年中的第几天.
Input
多组测试数据,每组输入年-月-日
Output
输出其在该年中对应的天数
Sample Input
2006-10-1
Sample Output
274
#include <stdio.h>
struct time{
int year;
int month;
int day;
};
int main(void)
{
struct time s1;
int n;
while(scanf("%d-%d-%d",&s1.year,&s1.month,&s1.day)!=EOF)
{
if(s1.year%4==0||s1.year%400==0)
{
if(s1.month==1)
printf("%d\n",s1.day);
if(s1.month==2)
printf("%d\n",s1.day+31);
if(s1.month==3)
printf("%d\n",s1.day+31+29);
if(s1.month==4)
printf("%d\n",s1.day+31+29+31);
if(s1.month==5)
printf("%d\n",s1.day+31+29+31+30);
if(s1.month==6)
printf("%d\n",s1.day+31+29+31+30+31);
if(s1.month==7)
printf("%d\n",s1.day+31+29+31+30+31+30);
if(s1.month==8)
printf("%d\n",s1.day+31+29+31+30+31+30+31);
if(s1.month==9)
printf("%d\n",s1.day+31+29+31+30+31+30+31+31);
if(s1.month==10)
printf("%d\n",s1.day+31+29+31+30+31+30+31+31+30);
if(s1.month==11)
printf("%d\n",s1.day+31+29+31+30+31+30+31+31+30+31);
if(s1.month==12)
printf("%d\n",s1.day+31+29+31+30+31+30+31+31+30+31+30);
}
else
{
if(s1.month==1)
printf("%d\n",s1.day);
if(s1.month==2)
printf("%d\n",s1.day+31);
if(s1.month==3)
printf("%d\n",s1.day+31+28);
if(s1.month==4)
printf("%d\n",s1.day+31+28+31);
if(s1.month==5)
printf("%d\n",s1.day+31+28+31+30);
if(s1.month==6)
printf("%d\n",s1.day+31+28+31+30+31);
if(s1.month==7)
printf("%d\n",s1.day+31+28+31+30+31+30);
if(s1.month==8)
printf("%d\n",s1.day+31+28+31+30+31+30+31);
if(s1.month==9)
printf("%d\n",s1.day+31+28+31+30+31+30+31+31);
if(s1.month==10)
printf("%d\n",s1.day+31+28+31+30+31+30+31+31+30);
if(s1.month==11)
printf("%d\n",s1.day+31+28+31+30+31+30+31+31+30+31);
if(s1.month==12)
printf("%d\n",s1.day+31+28+31+30+31+30+31+31+30+31+30);
}
}
return 0;
}