文章
84
粉丝
408
获赞
33
访问
877.7k
#include<iostream>
#include<cstdio>
using namespace std;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isleap(int y, int m)
{
//判断是否是闰二月
if (m != 2)
return false;
else if (y%400 == 0)
return true;
else if (y%100 != 0 && y%4 == 0)
return true;
else
return false;
}
void add_day(int& y, int& m, int& d, int count)
{
d += count;
while (1) {
if (isleap(y, m)) {
if (d > days[m]+1) {
d -= (days[m] + 1);
m += 1;
}
else
break;
}
else {
if (d > days[m]) {
d -= days[m];
m += 1;
}
else
break;
}
if (m == 13) {
y += 1;
m = 1;
}
}
}
int main()
{
int m;
cin >> m;
while (m--) {
int y, m, d, count;
cin >> y >> m >> d >> count;
add_day(y, m, d, count);
printf("%04d-%02d-%02d\n", y, m, d);
}
return 0;
}
登录后发布评论
#include<bits/stdc++.h>
using namespace std;
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool isleap(int y,int m)
{
if(m!=2)
return false;
else if(y%400==0)
return true;
else if(y%100!=0&&y%4==0)
return true;
else
return false;
}
void add_day(int &y,int &m,int &d,int count)
{
d+=count;
while(1)
{
if(isleap(y,m))
{
if(d>days[m]+1)
{
d-=(days[m]+1);
m+=1;
}
else break;
}
else
{
if(d>days[m])
{
d-=days[m];
m+=1;
}
else break;
}
if(m==13)
{
y+=1;
m=1;
}
}
}
int main()
{
int m;
cin>>m;
while(m--)
{
int y,m,d,count;
cin>>y>>m>>d>>count;
add_day(y,m,d,count);
printf("%04d-%02d-%02d\n",y,m,d);
}
return 0;
}