我被我自己的密码搞砸了。这个问题来自train.usaco.org:星期五十三号。
这是一个目标:也就是说,这个月的十三号在星期五登陆的频率比一周中的其他任何一天都要少吗?要回答这个问题,请编写一个程序,计算每个月的十三号在给定的N年内在星期日、星期一、星期二、星期三、星期四、星期五和星期六降落的频率。
这是我的密码:
/*
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;
}期望的
我的产量:-产量: 36 4233426 2293443 2293497 2293733 1996393719 -52161590现在:-Output: 38 34 35 33 33 34 33
我搞错什么了?任何帮助都是很好的,谢谢你的回应。
发布于 2015-01-14 09:15:11
每年从一月开始。你可以决定一月是0还是1,但是你应该是一致的。
https://stackoverflow.com/questions/27924138
复制相似问题