jilu1

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
bool isLeap(int year) {
    return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
}
int main() {
    //定义好平年和闰年每月的天数
    int monthDays[13][2] = {
        {0,0},{31,31},{28,29},{30,30},{31,31},{30,30},
        {31,31},{30,30},{31,31},{30,30},{31,31},{30,30},
        {31,31}
    };
    int time1, year1, month1, days1;
    int time2, year2, month2, days2;
    int numbers =1;
    // 输入两个日期
    cout << "输入两个日期,空格分隔";
    cin >> time1 >> time2;
    if (time1>time2){
        int temp = time1;
        time1 = time2;
        time2 = temp;

    }
    //拆解日期,分为年,月,号
    year1 = time1 / 10000; month1 = time1 / 100 % 100; days1 = time1 % 100;
    year2 = time2 / 10000; month2 = time2 / 100 % 100; days2 = time2 % 100;
    //第一个日期 累加到 第二个日期
    while (year1 < year2 || month1 < month2 || days1 < days2) {
        days1++;// 在第一个日期基础上  加一天
        //加一天后,相应的月,年可能也要做一定的变化
        if (days1 == monthDays[month1][isLeap(year1)]+1) {//当前号超过当前月最高天数:月份加1,号变成下月的1号
            month1++;
            days1 = 1;
        }
        if (month1 == 13) {//月份超过12个月 :年份加1,月份变成下年的1月
            year1++;
            month1 = 1;
        }
        numbers++;
    }
    cout << numbers << endl;
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值