对闰年 平年的优化
Sample Input
1985 1 20
2006 3 12
Sample Output
20
71
这里用到了二维数组,简直是棒极了!
但是要注意一下二维数组的初始化,
要在定义的时候全部初始化。
#include<stdio.h>
int Run[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
struct date
{
int year, month, day;
}date;
int main()
{
int i, dayth, RP;
while(scanf("%d%d%d", &date.year, &date.month, &date.day)!=EOF)
{
RP=(date.year%4==0&&date.year%100!=0 || date.year%400==0)?1:0;
if(date.month<1 || date.month>12 || date.day>Run[RP][date.month-1] || date.day<1)
{
printf("Input error!\n");
continue;
}
dayth = 0;
for(i=0; i<date.month-1; i++)
dayth+=Run[RP][i];
dayth+=date.day;
printf("%d\n", dayth);
}
}
posted on 2011-11-04 14:47 More study needed. 阅读(266) 评论(0) 编辑 收藏 举报