猜数

题目链接;https://vjudge.net/problem/POJ-2328

题目

两个小盆友玩猜数字游戏,一个小盆友心里想着1~10中的一个数字,另一个小盆友猜。如果猜的数字比实际的大,则告诉他“too high”,小则“too low”,正好则“right on”。直到猜对为止。但是那个猜的朋友怀疑他的小伙伴作弊,给他的回答不正确。于是让你根据他们的对话来判断一下这个小伙伴是否说谎。

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

 

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char ch[20];
	int n;
	int l=0,r=11;
	while(scanf("%d",&n)!=EOF&&n)
	{
		while(gets(ch)&&strcmp(ch,"right on"))
		{
			if(strcmp(ch,"too high")==0)
			{
				if(n<r)
				r=n;
			}
			if(strcmp(ch,"too low")==0)
			{
			
				if(n>l)
				l=n;
			}
			
			scanf("%d",&n);
		}
				if(n>l&&n<r)
				{
					cout<<"Stan may be honest"<<endl;
				}
				else
				{
					cout<<"Stan is dishonest"<<endl;
				}
				l=0,r=11;
	}
	return 0;
}

记得改成C语言交

代码

#include"stdio.h"
#include"string.h"
int main()
{
	int n,x,y,i,j,k;
	char s[20];
	int a[11];
	while(scanf("%d",&n)!=EOF&&n)
	{
	
	
			memset(a,0,sizeof(a));
			while(gets(s)&&strcmp(s,"right on"))
			{  
				if(!strcmp(s,"too high"))
				{
					  for(i=n;i<=10;i++)
					   a[i]=1;
				}
				if(!strcmp(s,"too low"))
				{
					for(i=n;i>=1;i--)
					 a[i]=1;
				}
				scanf("%d",&n);
			}
			if(a[n]==0)
			printf("Stan may be honest\n");
			else
			printf("Stan is dishonest\n");
	}
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值