这里面大家别想太多,可以采用空间换时间的方法,直接初始化就更加容易
#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;
}