自己写的很麻烦,直接套的日期模板,纯属为了撸一下模板
网上有很多简介的代码
#include<bits/stdc++.h>
#define ISYEAP(x) x%4==0&&x%100!=0||x%400==0?1:0
using namespace std;
int daymonth[13][2]={
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31
};
struct date{
int year;
int month;
int day;
void nextday(){
day++;
if(day>daymonth[month][ISYEAP(year)]){
day=1;
month++;
if(month>=13){
month=1;
year++;
}
}
}
};
int main(){
date temp;
int year,n;
while(scanf("%d %d",&year,&n)!=EOF){
int count=1;
temp.year=year;
temp.day=1;
temp.month=1;
while(count!=n){
temp.nextday();
count++;
}
printf("%04d-%02d-%02d\n",temp.year,temp.month,temp.day);
}
return 0;
}