题解 | #日期累加#
日期累加
https://www.nowcoder.com/practice/eebb2983b7bf40408a1360efb33f9e5d
bug:printf最后要输出换行 #include <iostream> #include<cstring> #include<algorithm> 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}; bool isLeap; isLeap = (year % 400 == 0) || (year % 4 ==0 && year % 100 != 0); if(isLeap){ dayOfMonth[2] = 29; } day++; if(day > dayOfMonth[month]){ day = 1; month++; } if(month > 12){ month = 1; year++; } } int main() { int n; int y,m,d,day; cin>>n; while(n--){ cin>>y>>m>>d>>day; while(day--){ NextDay(y,m,d); } printf("%04d-%02d-%02d\n",y,m,d); } return 0; }
王道考研机试 文章被收录于专栏
包含考研机试打卡表题目