| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水过35~~此题有一陷阱,贴代码如数据
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator