题解 | 打印日期

打印日期

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

#include <stdio.h>
using namespace std;
void Nextday(int year,int &month,int &day){
    int arr[]{0,31,28,31,30,31,30,31,31,30,31,30,31};
    bool isLeap=false;
    if(year%400==0||year%4==0&&year%100!=0){isLeap=true;}
    if(isLeap){arr[2]=29;}
    ++day;
    if(day>arr[month]){
        day=1;
        ++month;
    }
}
int main(){
    int year,days;
    while(scanf("%d%d",&year,&days)!=EOF){
        int count=1;
        int month=1;
        int day=1;
        if(days==1){
            printf("%d-%02d-%02d\n",year,month,day);
        }else{
        while(true){
            if(count==days){printf("%d-%02d-%02d\n",year,month,day);break;}
            Nextday(year,month,day);
            ++count;
        }
        }
    }
    return 0;
}

#shit#
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 15:58
投个小米提前批试试水,先投一个岗位看看形势,不行就再沉淀一下投第二个岗位,莫辜负
Java抽象带篮子:我嘞个骚刚,已经开始研发6g了吗
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务