Created
March 22, 2018 01:54
-
-
Save dgodfrey206/1d0f7b283a70d456d5d08ae8d3e08ed2 to your computer and use it in GitHub Desktop.
USACO problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
string convert(int n) { | |
string arr[]={"mon","tue","wed","thur","fri","sat","sun"}; | |
return arr[n%7]; | |
} | |
string mon_convert(int n){ | |
string arr[]={"jan","feb","mar","april","may","june","july","aug","sep","oct","nov","dec"}; | |
return arr[n%12]; | |
} | |
int main(){ | |
int day[7] = {}; | |
int n; cin >> n; n = 20; | |
for (int y=1900; y<1900+n; y++) { | |
bool isLeapYear = ((y%10 == 0 && (y/10)%10 == 0)) ? (y%400==0) : (y%4==0); | |
int dayCode = 0; | |
for (int i=0; i<12; i++) { | |
dayCode += 12; | |
//cout<<mon_convert(i)<<" convert("<<dayCode<<" % 7 = "<<(dayCode%7)<<") = "<<convert(dayCode)<<endl; | |
day[dayCode % 7]++; // increment frequency | |
// go to first day of next month | |
if (i == 1) { | |
int numDays = isLeapYear ? 28 : 27; | |
dayCode += (numDays - 12); | |
} | |
else if (i == 3 || i == 5 || i == 8 || i == 10) { | |
dayCode += 18; | |
} else { | |
dayCode += 19; | |
} | |
} | |
} | |
for (int i=0; i<7; i++) { | |
cout << day[i] << " "; | |
} | |
} | |
/* | |
mon=1 | |
tue=3 | |
wed=1 | |
thur=2 | |
fri=2 | |
sat=2 | |
sun=1 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment