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 |
高手指点.........感激不尽(分享方法。)// 2328.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <stdio.h> #include <string.h> int main(int argc, char* argv[]) { int a=0,b=11,c=0,n,low=0,high=11; //freopen("2328.txt","r",stdin); while(1) { scanf("%d",&n);getchar (); if(n==0) break; char s[21]; gets(s); if(strcmp(s,"too high")==0)//每输入一次就缩小b=high的范围 { if(high>=n) high=n; b=high;//printf("b=%d\n",b); } else if(strcmp(s,"too low")==0)//每输入一次就缩小a=low的范围 { if(low<=n) low=n; a=low;//printf("a=%d\n",a); } else if(strcmp(s,"right on")==0)//判断c是否在a b之间; { c=n;//printf("c=%d\n",c); for(int i=a+1;i<b;i++) if(i==c) { printf("Stan may be honest\n");//c是在a b之间; goto loop; } printf("Stan is dishonest\n");//c不在a b之间; loop:; low=0,high=11; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator