#include<stdio.h>
#include<string.h>
int main()
{
int year,month, day,temp,days=0; //temp为二月天数,days为总天数
scanf("%d-%d-%d",&year, &month, &day); //注意输入-号
//判断是否为闰年:1.被4整除不能被100整除 2.能被400整除
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
temp = 29;
else
temp = 28;
switch (month)
{
case 12:days += 30;
case 11:days += 31;
case 10:days += 30;
case 9:days += 31;
case 8:days += 31 ;
case 7:days += 30;
case 6:days += 31;
case 5:days += 30;
case 4:days += 31;
case 3:days += temp;
case 2:days += 31;
case 1:days += day;
} //days=前面几个月的总天数+day;
printf("%d", days);
}
判断一年中的第几天
于 2023-12-02 11:39:19 首次发布