Advertisement
Asif_Anwar

https://projecteuler.net/problem=19

Jan 30th, 2022
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1000000;
  5.  
  6. bool isLeap(int n)
  7. {
  8.     if(n%400==0) return true;
  9.    
  10.     if(n%100==0) return false;
  11.    
  12.     if(n%4==0) return true;
  13.    
  14.     return false;
  15. }
  16.  
  17. int main()
  18. {
  19.     map< int, int > days;
  20.     days[1] = days[3] = days[5] = days[7] = days[8] = days[10] = days[12] = 3;
  21.     days[4] = days[6] = days[9] = days[11] = 2;
  22.     days[2] = 0;
  23.     int curr = 2;
  24.     int ans = 0;
  25.     for(int i=1901; i<=2000; i++) {
  26.         for(int j=1; j<=12; j++) {
  27.             if(curr%7==0) {
  28.                 // cout << i << " " << j << "\n";
  29.                 ans++; 
  30.             }
  31.             // cout << i << " " << j << " " << curr << "\n";
  32.             int dd = days[j];
  33.             if(j==2 && isLeap(i)) {
  34.                 // cout << "Leap year: " << i << "\n";
  35.                 dd++;
  36.             }
  37.            
  38.             curr += dd;
  39.             // curr %= 8;
  40.         }
  41.     }
  42.     cout << ans << '\n';
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement