首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

初学者求北大acm1006题异常的原因,C写的

2012-04-15 
菜鸟求北大acm1006题错误的原因,C写的#include stdio.hint main(){int p,e,i,d,x,s0while(scanf(%d%d

菜鸟求北大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;
}

[解决办法]
估计是你题目意思理解的有问题。

C/C++ code
#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;} 

热点排行