POJ 2328 Guessing Game (a question that makes me cry !), Pojguessing

Source: Internet
Author: User
Tags control characters

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!




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.