编写一个日期类,要求按xxxx-xx-xx的格式输出日期,实现加一天的操作。
输入格式
第一行包含整数 T,表示共有 T 组测试数据。
每组数据占一行,包含 3个用空格隔开的整数,分别表示年月日。
输出格式
每组数据输出一行,一个结果,按xxxx-xx-xx的格式输出,表示输入日期的后一天的日期。
数据范围
输入日期保证合法且不会出现闰年。
年份范围 [1000,3000]
输入样例:
2
1999 10 20
2001 1 31
输出样例:
1999-10-21
2001-02-01
C++ 代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int n;
cin >> n;
while(n--){
int year,month,day;
cin >> year >> month >> day;
day++;
if(day > months[month]){
month++;
day = 1;
if(month > 12){
month = 1;
year++;
}
}
printf("%04d-%02d-%02d\n",year,month,day);
}
}