HDU Guess numbers

Source: Internet
Author: User

G-Guess numbers

Time limit:10000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64u

Description

Guessing number games 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

There are multiple sets of input data. 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 one row of output. 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

6 4815 2 1 5716 1 0 7842 1 0 4901 0 0 8585 3 3 8555 3 2 2 4815 0 0 2999 3 3 0

Sample Output

3585 not sure

——————-

The topic compares the water, mainly is the card a bit how to judge two numbers to have several numbers the same this question.

Later see the sample to understand what meaning.

The code is as follows:

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath>using namespace std; #define MAXN int a[maxn][4];       Inthow_correct (int A, int b) {int c[5],d[5];       C[1] = a/1000;       C[2] = a/100% 10;       C[3] = a/10% 10;       C[4] = a% 10;       D[1] = b/1000;       D[2] = b/100% 10;       D[3] = b/10% 10;       D[4] = b% 10;       int num = 0;       for (int i = 1; I <= 4; i++) if (c[i] = = D[i]) num++; return num;}       4815 (2 1) 3585inthow_many (int a, int b) {int c[5],d[5];       C[1] = a/1000;       C[2] = a/100% 10;       C[3] = a/10% 10;       C[4] = a% 10;       D[1] = b/1000;       D[2] = b/100% 10;       D[3] = b/10% 10;       D[4] = b% 10;       int num = 0;       BOOL flag_c[]= {False,false,false,false,false};       BOOL flag_d[]= {False,false,false,false,false}; for (int i = 1; I <= 4; i++) {if (c[i] = =D[i]) {num++;                    Flag_c[i] =true;             flag_d[i]= true;  }} for (int i = 1, i <= 4; i++) {if (flag_c[i] = = False) {for (int j = 1; j<=4;                                 J + +) {if (c[i] = = D[j] && Flag_d[j] = = False) {num++;                                 Flag_c[i] = true;                                 FLAG_D[J] = true;                          Break }}}} return num;}       /*64815 2 15716 1 07842 1 04901 0 08585 3 38555 3 2*/intmain () {int n;             while (CIN >> N) {if (n = = 0) break;       for (int i = 1; I <= n; i++) cin>> a[i][1] >> a[i][2] >> a[i][3]; for (int l = 1; l<=n; l++)//cout<< How_many (3585,a[l][1]) << ' \ t ' << how_correct (3585, a[l][1]) << Endl;              Return0;             int cnt = 0;             int k;             int ans;                    for (int j = 3585; j<= 9999; j + +) {int flag = 1; for (k = 1; k<=n; k++) {if (How_correct (J, a[k][1]) = = A[k][3] &&how_many (J, A[k ][1]) = = a[k][2])//{cout<<j << ' \ t ' << k<< ' \ t ' << "correct" &l                                 T;<endl;continue;}                          Continue;                                 else {flag = 0;                          Break                          }} if (flag = = 1) {cnt++;                    Ans= J;             }} if (cnt = = 1) cout<< ans << Endl; else cout<< "not sure" <<Endl; } return 0;}

HDU Guess numbers

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.