Advertisement
Dmaxiya

在小小的日历里面数呀数呀数 参考代码

Mar 30th, 2025
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 100 + 100;
  6. int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  7.  
  8. int cal(int year, int month, int day) {
  9.     int ret = 0;
  10.     for (int i = 0; i <= year; ++i) {
  11.         if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {
  12.             days[2] = 29;
  13.         } else {
  14.             days[2] = 28;
  15.         }
  16.         int maxMonth = (i == year ? month : 12);
  17.         for (int j = 1; j <= maxMonth; ++j) {
  18.             ret += (i == year && j == month ? day : days[j]);
  19.         }
  20.     }
  21.     return ret;
  22. }
  23.  
  24. int main() {
  25. #ifdef ExRoc
  26.     freopen("test.txt", "r", stdin);
  27. #endif // ExRoc
  28.     ios::sync_with_stdio(false);
  29.  
  30.     for (int i = 2026; i <= 10000; ++i) {
  31.         int sq = sqrt(i);
  32.         if (sq * sq == i) {
  33.             cout << cal(i, 1, 1) - cal(2025, 3, 29) << endl;
  34.             return 0;
  35.         }
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement