题解 | #计算日期到天数转换#
计算日期到天数转换
https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
#include<stdio.h>
int main(void)
{
int year,month,day;
scanf("%d %d %d",&year,&month,&day);
int monthday[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int daycnt=0;
if(year%400==0||year%100!=0&&year%4==0)
{
monthday[1]++;
}
for(int i=0;i<month-1;i++)
{
daycnt+=monthday[i];
}
daycnt+=day;
printf("%d",daycnt);
return 0;
}
int main(void)
{
int year,month,day;
scanf("%d %d %d",&year,&month,&day);
int monthday[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int daycnt=0;
if(year%400==0||year%100!=0&&year%4==0)
{
monthday[1]++;
}
for(int i=0;i<month-1;i++)
{
daycnt+=monthday[i];
}
daycnt+=day;
printf("%d",daycnt);
return 0;
}