HDU 1172. Guess the number "thinking shift, thinking practice" "enumeration" "August 8"

Source: Internet
Author: User

Guess numbers

Problem description Guess the number game is one of Gameboy's favorite games. The rules of the game are this: the computer randomly generates a four-digit number, and then the player guesses what the four-digit number is. Each guessing a number, the computer will tell the player to guess a few numbers, several of which are in the correct position.
For example, the computer randomly generates a number of 1122. If the player guesses 1234, because the two numbers exist in these two numbers at the same time, and 1 are in the same position in the two digits, the computer tells the player to guess 2 numbers, one in the correct position. If the player guesses 1111, then the computer will tell him to guess 2 numbers, 2 in the right position.
Now give you a Gameboy and computer dialogue process, and your task is to determine what this four-digit number is based on this conversation.

Input data has multiple groups. The first behavior of each group is a positive integer n (1<=n<=100), which indicates that there are n questions and answers in this conversation. In the next n rows, three integers per line are a,b,c. Gameboy Guess this four-digit number is a, and then the computer answers and guesses the B number, where C is in the correct position. When n=0, the input data ends.

Output each set of input data corresponds to a row of outputs. If this four-digit number is determined according to this conversation, the output of this four-digit number, if not, outputs "not sure".

Sample Input
64815 2 15716 1 07842 1 04901 0 08585 3 38555 3 224815 0 02999 3 30

Sample Output
3585Not sure
the topic is clearly described. The first idea is to infer, as he says, what the number is based on what is known, so that it falls into deep thinking because it does not know how to infer it. Correct idea: Enumerate the numbers between the 1000~10000 to see which of the several matches test instructions, one to be sure, and the more to be uncertain. The code is as follows:

#include <cstdio> #include <algorithm>using namespace std;struct pe{int num,same,cur;}    F[110];bool juge (int num,int k) {int mark[5]={0},num1[5],num2[5];    int cnt1=0,cnt2=0;        int a=num,b=f[k].num;//is doing this for the original saved number unchanged for (int i=3;i>-1;i--) {////separate save, easy to judge Num1[i]=a%10;        num2[i]=b%10;        a/=10;    b/=10;        } for (int i=0;i<4;i++) {if (num1[i]==num2[i]) cnt2++;                The for (int j=0;j<4;j++) {if (Num1[i]==num2[j]&&!mark[j]) {//mark[] records the location that has been compared mark[j]=1;                cnt1++;            Break }}} if (Cnt1==f[k].same&&cnt2==f[k].cur) return true;//number matches the current judging condition else return false;}    int main () {int n; while (scanf ("%d", &n) &&n) {for (int i=0;i<n;i++) scanf ("%d%d%d", &f[i].num,&f[i].sam        E,&f[i].cur);        int answer,cntt=0;        BOOL Key=true;          for (int i=1000;i<10000;i++) {for (int j=0;j<n;j++) {      Key=juge (I,J);                if (!key) break;//digit is not test instructions, jumps out, carries on the next number judgment} if (key) {//digit conforms to test instructions cntt++;            Answer=i;        } if (cntt>1) break;//found two can not be determined if (cntt==1) printf ("%d\n", answer);    else printf ("Not sure\n"); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1172. Guess the number "thinking shift, thinking practice" "enumeration" "August 8"

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.