注意1:闰年+1
注意2:8月往后规律不一样。
#include<stdio.h>
int ifleap(int a)
{
int k = 0;
if (((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0))
k = 1;
else
k = 0;
return k;
}
int main()
{
struct Day
{
int year;
int month;
int day;
}d;
scanf("%d %d %d", &d.year, &d.month, &d.day);
if (d.month > 12 || d.day > 31)
return 0;
int flag = 0;
int n;
if (d.month == 1)
n = d.day;
else if (d.month == 2)
n = 31 + d.day;
else if(d.month < 8)
{
if (d.month % 2 == 1)
n = d.month / 2 * 31 + d.day + d.month / 2 * 30 - 2;
else
n = d.month / 2 * 31 + d.day + (d.month - 1) / 2 * 30 - 2;
}
else
{
int j = 31 * 4 + 30 * 3 - 2;
if ((d.month-7) % 2 == 1)
n = (d.month-7) / 2 * 31 + d.day + (d.month-7) / 2 * 30 + j ;
else
n = (d.month-7) / 2 * 31 + d.day + (d.month-7 - 1) / 2 * 30 +j;
}
flag = ifleap(d.year);
if (flag == 1)
n += 1;
printf("%d", n);
system("pause");
return 0;
}
0.0分
0 人评分