Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水过35~~此题有一陷阱,贴代码

Posted by 0943041192 at 2011-02-09 15:40:26 on Problem 2328
如数据
7
too high
9
too high
8 
right on
答案是错误的。
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{
	//string str;
	char a[10];
	int x,y,guess;
	bool flag;
	while (1)
	{
		x = 0;
		y = 11;
		cin>>guess;
		if(guess == 0 )	break;
		while(getchar()!='\n');
		gets(a);
		flag = false;
		while (strcmp("right on",a)!=0)
		{
			if( !flag && strcmp(a,"too high")==0 )
			{
				if( guess <= y )
				{
					y = guess;
					y--;
					if( y < x )	flag = true;
				}
			}
			else if( !flag && 0==strcmp(a,"too low") )
			{
				if( guess >= x )
				{
					x = guess;
					x++;
					if( x > y )	flag = true;
				}
			}
			cin>>guess;
			while(getchar()!='\n');
			gets(a);
		}
		if( flag || guess>y || guess<x )	cout<<"Stan is dishonest"<<endl;
		else	cout<<"Stan may be honest"<<endl;
	}
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator