菜鸟求北大acm1006题错误的原因,C写的
#include <stdio.h>
int main()
{
int p,e,i,d,x,s=0;
while(scanf("%d%d%d%d",&p,&e,&i,&d)==4)
{
if(p==-1 && e==-1 && i==-1 && d==-1)break;
for(s++,x=d+1;x<=d+21252;x++)
{
if((x-p)%23==0 && (x-e)%28==0 && (x-i)%33==0)break;
}
printf("case %d:the next triple peak occurs in %d days.\n",s,x-d);
}
return 0;
}
[解决办法]
估计是你题目意思理解的有问题。
#include <iostream>using namespace std;int main(){ int p, e ,i, d, j, count = 1; while(cin >> p >> e >> i >> d) { if(p == -1 && e == -1 && i == -1 && d == -1) { break; } else if(p == 0 && e == 0 && i == 0) { cout << "Case " << count++ << ": the next triple peak occurs in " << 21252 - d << " days." << endl; } else { for(j = 1; j <= 21252; j++) { if(((j - i) % 33 == 0) && ((j - e) % 28 == 0) && ((j - p) % 23 == 0)) { break; } } if(j < d) { j = j + 21252; } int t = j - d; if(t > 21252) { t %= 21252; } if(t == 0) { t = 21252; } cout << "Case " << count++ << ": the next triple peak occurs in " << t << " days." << endl; } } return 0;}