POJ 2328--Guessing Game
Posted chuanwen-tech
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 2328--Guessing Game相关的知识,希望对你有一定的参考价值。
1 //模拟题,读错题,浪费一下午!/(ㄒoㄒ)/~~ 2 //此题的关键是最值更新,就不能说清楚嘛??? 3 #include<iostream> 4 #include<cstdio> 5 #include<algorithm> 6 using namespace std; 7 8 int main() 9 { 10 int n; 11 char a[10]; 12 int maxValue=11; 13 int minValue=0; 14 while(cin>>n&&n)//cin和%s遇到空格或换行会结束输入 15 { 16 getchar();//gets前不加这个,输不进字符串 17 gets(a); 18 19 if(a[0]==‘t‘)//ad hoc针对问题,发现特征 20 { 21 if(a[4]==‘h‘) 22 { 23 maxValue=min(maxValue,n); 24 } 25 else if(a[4]==‘l‘) 26 { 27 minValue=max(minValue,n); 28 } 29 } 30 else if(a[0]==‘r‘) 31 { 32 if(maxValue>n&&minValue<n) 33 cout<<"Stan may be honest"<<endl; 34 else 35 cout<<"Stan is dishonest"<<endl; 36 minValue=0; 37 maxValue=11; 38 } 39 } 40 return 0; 41 } 42 43 /* 44 #include<iostream> 45 #include<cstring> 46 #include<cstdio> 47 using namespace std; 48 49 const int len=10; 50 int a[len]={1,2,3,4,5,6,7,8,9,10}; 51 52 int main() 53 { 54 char s1[]="too high"; 55 char s2[]="too low"; 56 char s3[]="right on"; 57 int n; 58 char str[10]; 59 int *head=a; 60 int *tail=a+len-1; 61 62 while(scanf("%d",&n)!=EOF&&n)//string接收空格即结束 63 { 64 getchar(); 65 gets(str);//不加getchar就得不到这个字符串!!! 66 if(strcmp(str,s1)==0)//这个==0不写就找1个小时的错误吧/(ㄒoㄒ)/~~ 67 { 68 tail=a+n-1; 69 continue; 70 } 71 else if(strcmp(str,s2)==0) 72 { 73 head=a+n; 74 continue; 75 } 76 else if(strcmp(str,s3)==0) 77 { 78 if(*head>n||*tail<n) 79 { 80 cout<<"Stan is dishonest"<<endl; 81 head=a; 82 tail=a+len-1; 83 continue; 84 } 85 else 86 { 87 cout<<"Stan may be honest"<<endl; 88 head=a; 89 tail=a+len-1; 90 continue; 91 } 92 } 93 } 94 return 0; 95 } 96 */ 97 98 99 /*错误代码 100 #include<iostream> 101 #include<cstring> 102 #include<cstdio> 103 using namespace std; 104 105 const int len=10; 106 int a[len]={1,2,3,4,5,6,7,8,9,10}; 107 108 int main() 109 { 110 char s1[]="too high"; 111 char s2[]="too low"; 112 char s3[]="right on"; 113 int n; 114 char str[10]; 115 int *head=a; 116 int *tail=a+len-1; 117 while(scanf("%d",&n)!=EOF&&n) 118 { 119 cin.sync(); 120 getchar(); 121 gets(str); 122 cout<<str<<endl; 123 if(strcmp(str,s1)==0) 124 { 125 tail=a+n-1-1; 126 continue; 127 } 128 if(strcmp(str,s2)==0) 129 { 130 head=a+n; 131 continue; 132 } 133 if(strcmp(str,s3)==0) 134 { 135 if(*head==n&&*tail==n) 136 { 137 cout<<"Stan may be honest"<<endl; 138 head=a; 139 tail=a+len-1; 140 continue; 141 } 142 if(*head>n||*tail<n) 143 { 144 cout<<"Stan is dishonest"<<endl; 145 head=a; 146 tail=a+len-1; 147 continue; 148 } 149 } 150 } 151 return 0; 152 } 153 */
以上是关于POJ 2328--Guessing Game的主要内容,如果未能解决你的问题,请参考以下文章