#include <stdio.h>
int is_leap_year(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
else
return 0;
}
int gap_years(int year)
{
int i = 1990;
int sum = 0;
int gap_years = 0;
if (year == 1990)
return 0;
for (i = 1990; i < year; i++)
{
if (is_leap_year(i))
gap_years = 366;
else
gap_years = 365;
sum += gap_years;
}
return sum;
}
int gap_months(int year,int month)
{
int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days_in_leap_year[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int sum=0;
int i = 0;
if (month == 1)
return 0;
if (is_leap_year(year))
{
for (i = 1; i < month ; i++)
{
sum += days_in_leap_year[i];
}
return sum;
}
else
{
for (i = 1; i < month ; i++)
{
sum += days[i];
}
return sum;
}
}
int main()
{
int day = 0;
int month = 0;
int year = 0;
int gap = 0;
int a = 0;
scanf("%4d-%2d-%2d", &year, &month, &day);
if (day >= 32)
{
printf("Invalid input");
}
else
{
gap = gap_years(year) + gap_months(year, month) + day;
printf("%d\n", gap);
a = gap % 5;
printf("%d\n", gap_years(year));
printf("%d\n", gap_months(year, month));
printf("%d\n", day);
if (a <= 3 && a > 0)
printf("He is working");
else
printf("He is having a rest");
}
return 0;
}
标签:10,闰年,int,31,30,gap,数组,year,sum
From: https://blog.csdn.net/2301_80744520/article/details/136921931