题解 | #打印日期#

打印日期

https://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b

#include <cstdio>
int main() {
    int mdays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int m, n;
    while (scanf("%d%d", &m, &n) != EOF) {
        int year = m, month = 1, day = 1;
        while (--n) {
            bool isLeap = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
            if (isLeap) {
                mdays[2] = 29;
            } else {
                mdays[2] = 28;
            }
            day++;
            if (day > mdays[month]) {
                month++;
                day = 1;
                if (month > 12) {
                    year++;
                    month = 1;
                }
            }
        }
        printf("%04d-%02d-%02d\n", year, month, day);
    }
}

全部评论

相关推荐

贪食滴🐶:你说熟悉扣篮的底层原理,有过隔扣职业球员的实战经验吗
点赞 评论 收藏
分享
牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务