文章

55

粉丝

57

获赞

11

访问

11.3k

头像
打印日期 题解:C++
P1410 华中科技大学机试题
发布于2024年3月10日 00:12
阅读数 192

#include<stdio.h>

#include<iostream>

using namespace std;



int main(){

    int year,n;

    while(cin>>year>>n){

        int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

        bool isLeap = year%400==0 || year%100!=0 && year%4==0;

        if(isLeap){

            arr[2] = 29;

        }

        int month = 1;

        int t = 0;

        for(int i = 1; i<=n; i++){

            if(i > arr[month]){

                i = 1;

                n-=arr[month];

                month++;

            }

            t = i;

        }

        if(month<10 && t<10){

            printf("%d-0%d-0%d\n",year,month,t);

        }else if(month<10){

            printf("%d-0%d-%d\n",year,month,t);

        }else if(t<10){

            printf("%d-%d-0%d\n",year,month,t);

        }else{

            printf("%d-%d-%d\n",year,month,t);

        }

    }

}


登录查看完整内容


登录后发布评论

暂无评论,来抢沙发