一道简单的ACM程序题

DescriptionStanandOllieareplayingaguessinggame.Stanthinksofanumberbetween1and10andOll... Description
Stan and Ollie are playing a guessing game. Stan thinks of a number between 1 and 10 and Ollie guesses what the number might be. After each guess, Stan indicates whether Ollie's guess is too high, too low, or right on. After playing several rounds, Ollie has become suspicious that Stan cheats; that is, that he changes the number between Ollie's guesses. To prepare his case against Stan, Ollie has recorded a transcript of several games. You are to determine whether or not each transcript proves that Stan is cheating.

Input
Standard input consists of several transcripts. Each transcript consists of a number of paired guesses and responses. A guess is a line containing single integer between 1 and 10, and a response is a line containing "too high", "too low", or "right on". Each game ends with "right on". A line containing 0 follows the last transcript.

Output
For each game, output a line "Stan is dishonest" if Stan's responses are inconsistent with the final guess and response. Otherwise, print "Stan may be honest".

Sample Input
10
too high
3
too low
4
too high
2
right on
5
too low
7
too high
6
right on
0

Sample Output
Stan is dishonest
Stan may be honest

我的第一个代码在网上提示说是 wrong answer,,如下

#include "stdio.h"
#include "string.h"

void main()
{ char b[100][100];
int i,e,c[10],j=0,d;
scanf("%d",&e);
while(e!=0)
{ d=0;
c[j]=e;getchar();
gets(b[j]);
do{j++;
scanf("%d",&c[j]);getchar();
gets(b[j]);
}while(strcmp(b[j],"right on")!=0);
for(i=0;i<j;i++)
if(c[i]<c[j]&&strcmp(b[i],"too high")==0||
c[i]>c[j]&&strcmp(b[i],"too low")==0||c[j]<1||c[j]>10)
{d=1;break;}
j=0;
if(d==1)printf("Stan is dishonest\n");
else printf("Stan may be honest\n");
scanf("%d",&e);
}

}

第二个代码能在网上通过,如下

#include "stdio.h"
#include "string.h"

void main()
{ char b[100][100];
int i,e,c[100],j=0,min,max;
scanf("%d",&e);
while(e!=0)
{ min=1;max=10;
c[j]=e;getchar();
gets(b[j]);
do{j++;
scanf("%d",&c[j]);getchar();
gets(b[j]);
}while(strcmp(b[j],"right on")!=0);
for(i=0;i<j;i++)
if(strcmp(b[i],"too high")==0) max=c[i]<max?c[i]:max;
else if(strcmp(b[i],"too low")==0) min=c[i]>min?c[i]:min;

if(c[j]<max&&c[j]>min) printf("Stan may be honest\n");
else printf("Stan is dishonest\n");
scanf("%d",&e); j=0;
}

}

但是我认为这两个代码本质上都是一样的,我极度不明为什么会出现不同的结果,希望有空的各位能帮手看一下,还有如果有耐性看别人的代码而且有空指导我的其它ACM题目的,你要多少分我都可以给你(我还有其它号),有心人留下QQ,,以后联系,,感激不尽呀~~~
再说一下,我是大一的,菜鸟都可以指导我的,呵呵~~~
展开
 我来答
百度网友956cb0e
2008-12-31 · TA获得超过167个赞
知道答主
回答量:43
采纳率:0%
帮助的人:73.3万
展开全部
if(c[i]<c[j]&&strcmp(b[i],"too high")==0||
c[i]>c[j]&&strcmp(b[i],"too low")==0||c[j]<1||c[j]>10)
中c[i]<c[j]改成c[i]<=c[j];c[i]>c[j]改成c[i]>=c[j],应该不用我解释了吧。
你很有发展潜力,好好努力吧
上海华然企业咨询
2024-10-28 广告
作为上海华然企业咨询有限公司的一员,我们深知大模型测试对于企业数字化转型与智能决策的重要性。在应对此类测试时,我们注重数据的精准性、算法的先进性及模型的适用性,确保大模型能够精准捕捉市场动态,高效分析企业数据,为管理层提供科学、前瞻的决策支... 点击进入详情页
本回答由上海华然企业咨询提供
高金山
2008-12-30 · TA获得超过1万个赞
知道大有可为答主
回答量:4101
采纳率:0%
帮助的人:1778万
展开全部
http://youa.baidu.com/item/2dcf375866a396bc1412dc83
给1元钱,我帮你看!

要不然,让ivaniren帮你做吧;)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ivaniren
2008-12-25 · TA获得超过1472个赞
知道小有建树答主
回答量:1088
采纳率:0%
帮助的人:0
展开全部
高兄不地道!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式