简单模拟题。这代码长度应该还行,挺短了。
#include<iostream>
#include<cstdio>
using namespace std;
int getyear(int x)
{
if((x%4 == 0 && x%100 != 0) || x%400 == 0)
return 366;
return 365;
}
int month[2][13] = {
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}
};
int main()
{
int n;
while(~scanf("%d", &n))
{
int sy = 1970;
int x = n;
while(x >= 0)
x -= getyear(sy++)*86400;
printf("year: %d\n", sy-1970);
x = n;
int re = 0;
sy = 1970;
while(x >= 86400*getyear(sy))
{
x -= 86400*getyear(sy++);
re += 12;
}
int i = 0;
while(x >= 0)
{
int t = getyear(sy)-365;
x -= month[t][i]*86400;
i = ++i ==12 ? 0 : i;
re++;
}
printf("month: %d\n", re);
printf("day: %d\n", n / 86400 + 1);
}
}