Description
诗人H年少的时候就离开了故乡,等白发苍苍时才返回。有诗为证:“少小离家老大回,乡音无改鬓毛衰。儿童相见不相识,笑问客从何处来?” 假定诗人H离开故乡的日子为公元A年B月C日,返回的日子为公元X年Y月Z日。求诗人H离开故乡的总天数。
Input
输入为2个日期(年月日,且分别以空格隔开),都是公元后的有效值。 第一行:离开故乡的日期 第二行:返回故乡的日期
Output
离开故乡的天数(包括离开当天和返回当天)。离开故乡的天数(包括离开当天和返回当天)。
Sample Input
2009 10 31
2013 3 1
Sample Output
1218
#include<iostream>
using namespace std;
struct n {
int y;
int m;
int d;
};
int main() {
n a, b;
int ur[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int r[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
cin >> a.y >> a.m >> a.d;
cin >> b.y >> b.m >> b.d;
int t = 0;
int s = 0;
int u = 0;
for (int i = a.y; i < b.y; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
s = s + 366;
}
else s = s + 365;
}
if (a.y % 4 == 0 && a.y % 100 != 0 || a.y % 400 == 0)
for (int i = 1; i < a.m; i++) {
t = t + r[i];
}
else
for (int i = 1; i < a.m; i++) {
t = t + ur[i];
}
if (b.y % 4 == 0 && b.y % 100 != 0 || b.y % 400 == 0)
for (int i = 1; i < b.m; i++) {
u = u + r[i];
}
else
for (int i = 1; i < b.m; i++) {
u = u + ur[i];
}
cout << s + u - t - a.d + b.d + 1 << endl;
}