显示原始代码
#include <iostream>
using namespace std;
int a[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 y1 = 2005, m1 = 10, d1 = 9;
int y2 = 2023, m2 = 12, d2 = 1;
int res = 0;
int main() {
for (int i = y1 + 1; i <= y2 - 1; i++) {
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
res += 366;
else
res += 365;
}
if ((y2 % 4 == 0 && y2 % 100 != 0) || y2 % 400 == 0) {
for (int i = 1; i <= m2 - 1; i++) {
res += a[1][i];
}
} else {
for (int i = 1; i <= m2 - 1; i++) {
res += a[0][i];
}
}
if ((y1 % 4 == 0 && y1 % 100 != 0) || y1 % 400 == 0) {
for (int i = 12; i >= m1 + 1; i--) {
res += a[1][i];
}
} else {
for (int i = 12; i >= m1 + 1; i--) {
res += a[0][i];
}
}
if ((y1 % 4 == 0 && y1 % 100 != 0) || y1 % 400 == 0) {
res += a[1][m1] - d1 + 1;
} else {
res += a[0][m1] - d1 + 1;
}
res += d2; cout << res;
return 0;
}