题解 | #打印日期#
打印日期
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); } }