文章
27
粉丝
86
获赞
11
访问
31.0k
C++
逐个单独处理年末和月末的情况
- #include <iostream>
- #include <iomanip>
- using namespace std;
- bool isLeapYear(int year){
- return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
- }
- void show(int year, int month, int day){
- if(month == 12 && day == 31){
- year += 1;
- month = 1;
- day = 1;
- }
- else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10) && day == 31){
- month += 1;
- day = 1;
- }
- else if((month == 4 || month == 6 || month == 9 || month == 11) && day == 30){
- month += 1;
- day = 1;
- }
- else if(month == 2 && day == 29 && isLeapYear(year)){
- month += 1;
- day = 1;
- }
- else if(month == 2 && day == 28 && !isLeapYear(year)){
- month += 1;
- day = 1;
- }
- else{
- day += 1;
- }
- cout << setw(4) << setfill('0') << year << "-" << setw(2) << setfill('0') << month << "-" << setw(2) &l...
登录后发布评论
暂无评论,来抢沙发