题解 | #打印日期#

打印日期

https://www.nowcoder.com/practice/b1f7a77416194fd3abd63737cdfcf82b

#include <iostream>
using namespace std;
int main() {
    int year,num;
    int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    while(cin>>year>>num){
        months[2]=28;
        if((year%400==0)||(year%4==0&&year%100!=0))
            months[2]=29;
        for(int i =1;i<=12;i++){
            if(months[i]>=num){
                cout<<year<<"-"<<(i<=9?"0"+to_string(i):to_string(i))<<"-"<<(num<=9?"0"+to_string(num):to_string(num))<<endl;
                break;
            }else{
                num-=months[i];
            }
        }
    }
}
// 64 位输出请用 printf("%lld")

qd

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务