1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| #include <bits/stdc++.h> #define endl '\n' using namespace std; struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } }_io; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll;
bool leapyear[10005], a_year[10005]; bool is31[13] = { 0,1,0,1,0,1,0,1,1,0,1,0,1 }; ll sum[10005], l_mon[13], n_mon[13]; ll ss(ll x) { ll res = 0; while (x != 0) { res *= 10; res += x % 10; x /= 10; } return res / 10; } void init() { for (ll i = 2000; i <= 9999; ++i) { if (i / 10 == 202 || ss(i) == 202) a_year[i] = 1; if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) leapyear[i] = 1; }
for (ll i = 2000; i <= 9999; ++i) { if (a_year[i]) sum[i] += leapyear[i] ? 366 : 365; else { if (i % 10 == 2) sum[i] += leapyear[i] ? 29 : 28; else ++sum[i]; ++sum[i]; } sum[i] += sum[i - 1]; }
for (ll i = 1; i <= 12; ++i) { if (i == 2) l_mon[i] = 29; else if (is31[i]) l_mon[i] = 31; else l_mon[i] = 30; l_mon[i] += l_mon[i - 1]; }
for (ll i = 1; i <= 12; ++i) { if (i == 2) n_mon[i] = 28; else if (is31[i]) n_mon[i] = 31; else n_mon[i] = 30; n_mon[i] += n_mon[i - 1]; } } bool judge(ll m1, ll d1, ll m2, ll d2, ll m, ll d) { if (m1 < m && m < m2) return 1; if (m1 < m && m == m2 && d <= d2) return 1; if (m1 == m && m < m2 && d >= d1) return 1; if (m1 == m2 && m1 == m && d1 <= d && d <= d2) return 1; return 0; } ll cul(ll y, ll m1, ll d1, ll m2, ll d2) { ll res = 0; if (m1 < m2) { if (leapyear[y]) if (m2 - 1 >= m1) res += l_mon[m2 - 1] - l_mon[m1]; if (!leapyear[y]) if (m2 - 1 >= m1) res += n_mon[m2 - 1] - n_mon[m1]; if (m1 == 2) res += (leapyear[y] ? 29 : 28) - d1 + 1; else res += (is31[m1] ? 31 : 30) - d1 + 1; res += d2; } else res += d2 - d1 + 1; return res; }
int main() { init(); ll T; scanf("%lld", &T); while (T--) { ll y1, m1, d1, y2, m2, d2; scanf("%lld%lld%lld%lld%lld%lld", &y1, &m1, &d1, &y2, &m2, &d2);
ll ans = 0; if (y2 - 1 >= y1) ans += sum[y2 - 1] - sum[y1];
if (y1 != y2) { if (a_year[y1]) ans += cul(y1, m1, d1, 12, 31); else { if (y1 % 10 == 2) { if (m1 < 2) ans += leapyear[y1] ? 29 : 28; else if (m1 == 2) ans += (leapyear[y1] ? 29 : 28) - d1 + 1; } else if (judge(m1, d1, 12, 31, 2, 2)) ++ans; if (judge(m1, d1, 12, 31, 12, 2)) ++ans; }
if (a_year[y2]) ans += cul(y2, 1, 1, m2, d2); else { if (y2 % 10 == 2) { if (m2 > 2) ans += leapyear[y2] ? 29 : 28; else if (m2 == 2) ans += d2; } else if (judge(1, 1, m2, d2, 2, 2)) ++ans; if (judge(1, 1, m2, d2, 12, 2)) ++ans; } } else { if (a_year[y1]) ans += cul(y1, m1, d1, m2, d2); else { if (y1 % 10 == 2) { if (m1 < 2 && 2 < m2) ans += leapyear[y1] ? 29 : 28; else if (m1 == 2 && m2 > 2) ans += (leapyear[y1] ? 29 : 28) - d1 + 1; else if (m1 < 2 && m2 == 2) ans += d2; else if (m1 == m2 && m1 == 2) ans += d2 - d1 + 1; } else if (judge(m1, d1, m2, d2, 2, 2)) ++ans; if (judge(m1, d1, m2, d2, 12, 2)) ++ans; } }
cout << ans << endl; } return 0; }
|