Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main()
{
int years, month, day;
int a[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int b[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
while (scanf("%d/%d/%d", &years, &month, &day) != EOF)
{
int sum = 0;
for (int i = 0; i < month - 1; i++)
{
if (years % 4 == 0 && years % 100 != 0 || years % 400 == 0)
sum += b[i];
else
sum += a[i];
}
sum = sum + day;
printf("%d\n",sum);
}
system("pause");
return 0;
}