文章

55

粉丝

57

获赞

11

访问

10.8k

头像
日期累加 题解:
P1446 北京理工大学机试题
发布于2024年3月15日 11:51
阅读数 168

#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
    int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    int n;
    cin >> n;
    while(n--){
        int year, month, day, count;
        cin >> year >> month >> day >> count;

        for(int i = 0; i<count; i++){
            bool isLeap = year % 400 == 0 || (year % 100 != 0 && year % 4 == 0);
            if(isLeap){
                arr[2] = 29;
            } else {
                arr[2] = 28;
            }

            day++;
            if(day > arr[month]){
                month++;
                day = 1;
            }
            if(month > 12){
                year++;
                month = 1;
            }
        }

        printf("%d-%02d-%02d\n", year, month, day);
    }

    return 0;
}
 
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发