题解 | #日期累加#
日期累加
https://www.nowcoder.com/practice/eebb2983b7bf40408a1360efb33f9e5d
#include <cstdio> int main() { int m; int mdays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int year, month, day, after; while (scanf("%d", &m) != EOF) { for (int i = 0; i < m; ++i) { scanf("%d%d%d%d", &year, &month, &day, &after); while (after--) { 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); } } }