题解 | #日期类#

日期类

https://www.nowcoder.com/practice/130aa2d7d1f5436b920229dca253893b

#include <cstdio>
int main() {
    int n;
    int mdays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    while (scanf("%d", &n) != EOF) {
        int year, month, day;
        for (int i = 0; i < n; ++i) {
            scanf("%d%d%d", &year, &month, &day);
            day++;
            if (day > mdays[month]) {
                month++;
                day = 1;
                if (month > 12) {
                    year++;
                    month = 1;
                }
            }
            printf("%04d-%02d-%02d\n", year, month, day);
        }
    }
}

全部评论

相关推荐

挣K存W养DOG:他真的很中意你,为什么不回他
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务