POJ 2328 Guessing Game (a question that makes me cry !), Pojguessing
[Description]: it is just the number of guesses. I think you will definitely watch such a similar program on TV.
[Analysis]: WA should have been a simple question, but because I am also very confused, there is a small problem in the input of control characters, so it took a long time! I think a little too much! Or do few questions.
This is the code from WA to death !!
// WA code !! # Include <iostream> # include <cstring> using namespace std; int main () {int a; char ans [10]; while (1) {bool flag = false; int Max = 100; int Min = 0; cin> a; if (a = 0) break; getchar (); // Add this here! Gets (ans); while (1) {if (strcmp (ans, "right on") = 0) break; if (strcmp (ans, "too high ") = 0 & a <Max) // Add a <Max here! Max = a; if (strcmp (ans, "too low") = 0 & a> Min) // the same is true here !! Min = a; cin> a; getchar (); // note that you need to add this here! Gets (ans);} if (a <Min | a> Max) printf ("Stan is dishonest \ n "); elseprintf ("Stan may be honest \ n");} return 0 ;}
This is the AC code:
// AC code !! # Include <iostream> # include <cstring> using namespace std; int main () {int a; char ans [10]; while (1) {bool flag = false; int Max = 100; int Min = 0; cin> a; if (a = 0) break; getchar (); // Add this here! Gets (ans); while (1) {if (strcmp (ans, "right on") = 0) break; if (strcmp (ans, "too high ") = 0 & a <Max) Max = a; if (strcmp (ans, "too low") = 0 & a> Min) Min =; cin> a; getchar (); // note that you need to add this here! Gets (ans);} if (a> Min & a <Max) printf ("Stan may be honest \ n "); elseprintf ("Stan is dishonest \ n");} return 0 ;}
Are the two codes different? In fact, it's just that my first WA code has an equal sign missing. It should be
If (a <= Min | a> = Max) // you must have an equal sign !!! Printf ("Stan is dishonest \ n ");
This boundary is the most prone to errors !! Pay more attention in the future!