I am screwed with my own code. This problem is from train.usaco.org: Friday The Thirteen.
Here is the objective: That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years.
And here is my code:
/*
ID: erdemtu2
PROG: friday
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int horwuul(int month, int year){
if(month == 2)
return ((year % 4) || (!(year % 100) && ((year+300) % 400))) ? 28 : 29;
switch(month){
case 3:
case 5:
case 9:
case 11:
return 30;
break;
default:
return 31;
break;
}
}
int main() {
//freopen("friday.in", "r", stdin);
//freopen("friday.out", "w", stdout);
int a, i, j;
cin >> a;
if(a < 0) a = 0;
if(a > 400) a = 400;
int ans[7]={0};
//was int ans[7];
int q=0, month=0;
for(i = 0; i < a; i++)
for(j = 0; j < 12; j++){
ans[((q + 6) % 7)]++;
q = (q + horwuul(j, i)) % 7;
}
for(i = 0; i < 7; i++){
cout << ans[(i + 6) % 7];
cout << " ";
}
return 0;
}
Expected
- Input: 20
- Output: 36 33 34 33 35 35 34
Mine was: - Output: 36 4233426 2293443 2293497 2293733 1996393719 -52161590 now: -Output: 38 34 35 33 33 34 33
And what am i mistaking on? Any help would be great, and thanks for response.