题解 | #打印日期#

打印日期

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);
    }
}

全部评论

相关推荐

AFBUFYGRFHJLP:直接去美帝试试看全奖phd吧
点赞 评论 收藏
分享
totoroyyw:千年老妖😂
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务