mickypinata

USACO-T003: Friday the Thirteenth

Sep 20th, 2021
598
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ID: mickyta1
  3. TASK: friday
  4. LANG: C++
  5. */
  6.  
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9.  
  10. int cnt[7], month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  11.  
  12. bool isLeap(int x){
  13.     if(x % 400 == 0){
  14.         return true;
  15.     } else if(x % 100 == 0){
  16.         return false;
  17.     }
  18.     return x % 4 == 0;
  19. }
  20.  
  21. int main(){
  22.  
  23.     freopen("friday.in", "r", stdin);
  24.     freopen("friday.out", "w", stdout);
  25.  
  26.     int n;
  27.     scanf("%d", &n);
  28.     int cur = 0;
  29.     for(int i = 1900; i <= 1900 + n - 1; ++i){
  30.         for(int j = 1; j <= 12; ++j){
  31.             ++cnt[cur];
  32.             if(j == 2 && isLeap(i)){
  33.                 cur = (cur + 29) % 7;
  34.             } else {
  35.                 cur = (cur + month[j]) % 7;
  36.             }
  37.         }
  38.     }
  39.     for(int i = 0; i < 6; ++i){
  40.         cout << cnt[i] << ' ';
  41.     }
  42.     cout << cnt[6] << '\n';
  43.  
  44.     fclose(stdin);
  45.     fclose(stdout);
  46.  
  47.     return 0;
  48. }
  49.  
RAW Paste Data