题目描述
编写一个日期类,要求按xxxx-xx-xx 的格式输出日期,实现加一天的操作。
输入描述:
输入第一行表示测试用例的个数m,接下来m行每行有3个用空格隔开的整数,分别表示年月日。测试数据不会有闰年。
输出描述:
输出m行。按xxxx-xx-xx的格式输出,表示输入日期的后一天的日期。
示例1
输入
2
1999 10 20
2001 1 31
输出
1999-10-21
2001-02-01
备注:
注意个位数日期前面要有0
代码:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int main()
{
int months[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int n , year , month , day;
while(cin >> n){
for(int i = 0; i < n; i++){
cin >> year >> month >> day;
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
months[1] = 29;
}else{
months[1] = 28;
}
if((day + 1) > months[month - 1]){
month++;
if(month > 12){
year++;
}
month = month % 12;
day = 1;
}else{
day++;
}
cout << year << "-";
if(month < 10){
cout << "0" << month << "-";
}else{
cout << month << "-";
}
if(day < 10){
cout << "0" << day << endl;;
}else{
cout << day << endl;
}
}
}
return 0;
}