题解 | #打印日期#
打印日期
https://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b
#include<iostream> using namespace std; void nextDay(int &year,int &month,int &day){ int dayOfMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if(year%400==0 || (year%4==0 && year%100!=0)){ //闰年 dayOfMonth[2]=29; } else dayOfMonth[2]=28; day++; if(day>dayOfMonth[month]){ day=1; month++; } if(month>12){ month=1; year++; } } int main(){ int m,n; while(scanf("%d%d",&m,&n)!=EOF){ int count=1; int mon=1; int day=1; while(count<n){ nextDay(m,mon,day); count++; } printf("%d-%02d-%02d\n",m,mon,day); } return 0; }