文章
105
粉丝
69
获赞
117
访问
56.7k
#include<bits/stdc++.h>
using namespace std;
int y, d;
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int s[13]; // month数组的前缀和
bool cheak(int year)
{
return (year % 4 == 0 && year % 100 != 0 )|| year % 400 == 0;
}
int main()
{
for(int i = 1; i <= 12; i ++) //预处理前缀和
s[i] += (s[i - 1] + month[i]);
while(cin >> y >> d)
{
int m;
if(cheak(y)) //闰年多一天
for(int i = 2; i <= 12; i ++)
s[i] += 1;
for(int i = 1; i <= 12; i ++)
if(d <= s[i])
{
m = i;
break;
}
if(m > 1) d = d - s[m - 1];
printf("%04d-%02d-%02d\n", y, m, d);
if(cheak(y)) //还原前缀合
for(int i = 2; i <= 12; i ++)
s[i] -= 1;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发