每次读取数据判断: a. too high:x是否比上界小?h=x : continue b. too low:x是否比下界大?l=x : continue c. right on:x是否在范围内?诚实:不诚实
笔记
最开始上下界不能用1和10000000
代码
#include<cstdio>#include<cstring>usingnamespace std;intmain(){int x, h, l;char order[10];memset(order,'\0',sizeof(order));while(1){scanf("%d",&x);getchar();if(x==0)break;scanf("%[^\n]%*c", order);
h =10000010;
l =0;while(strcmp(order,"right on")!=0){if(strcmp(order,"too high")==0&& x<h)
h = x;elseif(strcmp(order,"too low")==0&& x>l)
l = x;scanf("%d",&x);getchar();scanf("%[^\n]%*c", order);}if(x>l && x<h)printf("The guy may be honest\n");elseprintf("The guy is dishonest\n");}return0;}
Problem 1575 小学生的游戏.思路设置范围,根据小明的反馈不断调整范围,直到right on每次读取数据判断:a. too high:x是否比上界小?h=x : continueb. too low:x是否比下界大?l=x : continuec. right on:x是否在范围内?诚实:不诚实笔记最开始上下界不能用1和10000000代码#include&l...