题解 | 日期类

#include <bits/stdc++.h>
#include <cstdio>
using namespace std;

int date[13]={0,31,28,31,30,31,30,31,31,30,31};

int main(){
    int m;
    while(cin>>m){
        while(m--){
            int year,month,day;
            cin>>year>>month>>day;
            if(++day>date[month]){
                day=1;
                month++;
                if(month>12){
                    month=1;
                    year++;
                }
            }
            printf("%04d-%02d-%02d\n",year,month,day);
        }
    }
}

没有闰年,就直接算就完事了,也不用写闰年判断

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务