请你计算出 xx 年 yy 月 zz 日是 xx 年的第几天。
请注意闰年对答案的影响。
输入格式
一行三个整数,xx,yy 和 zz。(1583\le x\le 21001583≤x≤2100)。数据保证输入合法。
输出格式
一个整数,表示是第几天。
输入
2016 3 1
输出
61
输入
1900 3 1
输出
60
思路
需要考虑闰年平年,闰年可被4整除,但不能被100或400整除。用switch 语句和for循环语句进行计算
#include <stdio.h>
int main()
{
int year, month, day;
int s=0;
scanf("%d%d%d", &year,&month,&day);
switch(month)
{
case12: s+=30; //加上11月的30天
case 11: s+=31; //加上10月的31天
case 10: s+=30; //加上 9月的30天
case 9: s+=31;
case 8: s+=31;
case 7: s+=30;
case 6: s+=31;
case 5: s+=30;
case 4: s+=31;
case 3: s+=28; //先按平年算,加上2月的28天
case 2: s+=31; //加上 1月的31天
case 1: s+=day; //加上当月天数
}
if((year%4==0 && year%100!=0 || year%400==0) && month>=3)
s++;
printf("%d\n",s);
return 0;
}