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
| #include <bits/stdc++.h> using namespace std;
bool leap(int y) { if (y % 400 == 0) return 1; if (y % 100 == 0) return 0; if (y % 4 == 0) return 1; return 0; }
int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int y, m, d; cin >> y >> m >> d; int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (y <= 0 or m < 1 or m > 12) { cout << "error"; return 0; }
if (leap(y)) days[2] = 29;
if (d < 1 or d > days[m]) { cout << "error"; return 0; }
int ans = 0; for (int i = 1; i < m; i++) ans += days[i];
cout << ans + d; }
|