题目来源: 百练 计算两个日期之间的天数
#include <iostream>
using namespace std;
int num[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
int isLeap(int Year)
{
return (Year % 4 == 0 && Year % 100 != 0) || Year % 400 == 0;
}
int main()
{
int startYear, startMonth, startDay;
cin >> startYear >> startMonth >> startDay;
int endYear, endMonth, endDay;
cin >> endYear >> endMonth >> endDay;
int ans = 0;
while(startDay < endDay || startMonth < endMonth || startYear < endYear)
{
startDay++;
if(startDay > num[isLeap(startYear)][startMonth])
{
startMonth++;
startDay = 1;
}
if(startMonth == 13)
{
startYear++;
startMonth = 1;
}
ans++;
}
cout << ans << endl;
return 0;
}