文章

8

粉丝

0

获赞

28

访问

1.2k

头像
日期累加 题解:(我是按照月份处理的)需要考虑:1、需要将前面的输入存放下来,后面再一条一条处理;2、处理的时候需要同时考虑是否跨月?跨月的同时是否跨年?3、平年和闰年的处理;
P1446 北京理工大学机试题
发布于2026年3月17日 18:35
阅读数 118

#include<iostream>
#include<vector>
using namespace std;

// 判断闰年
bool isLeapYear(int year){
    return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}

int main(){

    int sampleCount; // 输入的样例个数
    vector<int> years;
    vector<int> months;
    vector<int> days;
    vector<int> addDays; // 累加的天数
    cin >> sampleCount;

    // 保存输入的值,后面再循环处理后进行输出
    // 然后后面再一个一个输出,而不是输入一条输出一条,所以要进行保存再读取
    for(int i = 0; i < sampleCount; i++){
        int yearInput, monthInput, dayInput, daysToAdd;
        cin >> yearInput >> monthInput >> dayInput >> daysToAdd;
        years.push_back(yearInput);
        months.push_back(monthInput);
        days.push_back(dayInput);
    &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发