#include<iostream> using namespace std; int daytab[2][31] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; int main() { int year; int count; int month, day; int flag = -1; while (cin >> year >> count) { flag = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); for (int i = 1; i < 13; i++) { if (count - daytab[flag][i] > 0) { count -= daytab[flag][i]; continue; } else if (count - daytab[flag][i] == 0) { month = i; day = daytab[flag][i]; break; } else { month = i; day = count; break; } } printf("%d-%02d-%02d\n", year, month, day); //0表示左边补0,2表示位宽 //字符串格式化各种精度/补0 //https://www.cnblogs.com/lidabo/p/5463179.html //%[标志][输出最小宽度][.精度][长度]类型 } }
C语言格式化字符串:https://www.cnblogs.com/lidabo/p/5463179.html
%[标志][输出最小宽度][.精度][长度]类型