usaco Friday the Thirteenth solution: http://ideone.com/ClCFT6
#include <iostream> #include <cstdio> using namespace std; int main() { int n, l=1, w[10]={0}; scanf("%d", &n); for(int i=1900; i<1900+n; i++) { for(int j=0; j<12; j++) { if(j==3 || j==5 || j==8 || j==10) { for(int k=0; k<30; k++) { l++, l%=7; if(k==12) w[l]++; } } else if(j!=1) { for(int k=0; k<31; k++) { l++, l%=7; if(k==12) w[l]++; } } else { if(i%400==0 || (i%100!=0 && i%4==0)) { for(int k=0; k<29; k++) { l++, l%=7; if(k==12) w[l]++; } } else { for(int k=0; k<28; k++) { l++, l%=7; if(k==12) w[l]++; } } } } } for(int i=0; i<6; i++) printf("%d ", w[i]); printf("%d\n", w[6]); return 0; }
note: dont forget to add your usacogate ID, PROG, LANG comment at the beginning of the code. and freopen() stuff in main() part.
No comments:
Post a Comment