#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;
}
354

被折叠的 条评论
为什么被折叠?



