题解 | #日期类#
日期类
https://www.nowcoder.com/practice/130aa2d7d1f5436b920229dca253893b
#include <iostream> using namespace std; int main() { int n;cin>>n; while(n--){ int year,month,day; cin>>year>>month>>day; int arr[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if(year %400==0 || ((year%100 !=0)&&(year%4 == 0))){ arr[2]++; } if(++day>arr[month]){ day = 1; month++; if(month>12){ month=1; year++; } } cout<<year<<"-"; cout<<(month>=10?to_string(month):"0"+to_string(month))<<"-"; cout<<(day>=10?to_string(day):"0"+to_string(day))<<endl; } } // 64 位输出请用 printf("%lld")
qd