题解 | #打印日期#
打印日期
https://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b
简单模拟题,放松心态啦!
#include <iostream> #include <algorithm> using namespace std; int main() { int year, d; while (cin >> year >> d) { int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) days[2] += 1; for (int i = 1; i <= 12; i++) { if (d <= days[i]) { printf("%04d-%02d-%02d\n", year, i, d); break; } d -= days[i]; } } }