Guessing Game

FJNU.1509
PKU.2328

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

Source
5 July, 2003 - Waterloo

My Program

#include < stdio.h >
#include
< string .h >
main()
{
  
int high=11,low=0,guess,n=0,i,a[1000];
  
char str[5000];
  scanf(
"%d",&guess);
  
while(guess!=0)
  
{
    getchar();
    gets(str);
    a[n]
=0;
    
while(1)
      
{
    
if(!strcmp(str,"too high"))
          
{
        
if(guess<low) a[n]=0;
            
else if(guess<high) high=guess;
          }

        
if(!strcmp(str,"too low"))
          
{
        
if(guess>high) a[n]=0;
            
else if(guess>low) low=guess;
          }

        
if(!strcmp(str,"right on"))
      
if((guess<high)&&(guess>low)) a[n]=1;
    
break;
      }

    
if(!strcmp(str,"right on")) 
      
{n++;high=11;low=0;}
    scanf(
"%d",&guess);
    
if(guess==0break;
  }

  
for(i=0;i<n;i++)
    
if(a[i]==0)
      printf(
"Stan is dishonest ");
    
else
      printf(
"Stan may be honest ");
}

YOYO's Note: 
简单的模拟而已……大一时写的——
当时的我写代码多不规范阿~连return 0都没有 - -

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值