题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
int is_run(int year)
{
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
{
return 1;
}
return 0;
}
int main()
{
int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };//平年
int year = 0;
int month = 0;
int day = 0;
while (scanf("%d%d%d", &year, &month, &day) != EOF)
{
int sum = 0;
int ret = is_run(year);
if (month > 2)
{
sum+=ret;
}
int i = 0;
for (i = 0; i < month-1; i++)
{
sum += arr[i];
}
sum += day;
printf("%d\n", sum);
}
return 0;
}