题解 | 日期累加

日期累加

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

#include <stdio.h>
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;
    }
    if(month>12){
        month=1;
        ++year;
    }
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
    int year,month,day;
    scanf("%d%d%d",&year,&month,&day);
    int num;
    scanf("%d",&num);
    for(int j=0;j<num;++j){
        Nextday(year,month,day);
    }
    printf("%04d-%02d-%02d\n",year,month,day);
    }
    return 0;
}

#shit#
全部评论

相关推荐

点赞 评论 收藏
分享
在debug的柠檬精很迷人:好消息:现在HR挑三拣四 15年后 HR跪着求要简历 坏消息:被挑的是这代人,到时候求人的也是这代人。真好。
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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