题解 | #打印日期#
打印日期
https://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b
#include <cstdio> int main(){ int year,n; int monday[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; while (scanf("%d%d",&year,&n) != EOF){ int mon = 1; int day = 1; for (int i = 0; i < n - 1; ++i) { bool isyear = year % 400 == 0 || year % 100 != 0 && year % 4 == 0; if (isyear){ monday[2] = 29; } else{ monday[2] = 28; } ++day; if (day > monday[mon]){ ++mon; day = 1; if (mon > 12){ mon = 1; ++year; } } } printf("%04d-%02d-%02d\n",year,mon,day); } }