Hnu number guessing

Source: Internet
Author: User

Describe

Number guessing is a computer game. First, the computer chooses four different digits, you need to guess these four digits in the fewest times,for each guess, The computer would show a judgement in the form of "#A #b" and "#" is a number 0~4. "#A" shows how many digits you guessed with both correct value and position. "#B" shows how many digits you guessed with correct value. For example, the computer chose 1234, and you guessed 6139, the computer would show "1A2B" for You has number "1" correct Value but wrong position and number ' 3 ' correct value with correct position. Thus the computer gives you the judgement of "1a2b". Now there are memorized the digits you guessed and the judgements you got, you feel like you can figure out the correct ans Wer. Life was filled with wisdom, isn ' t it?

Input

There is several test cases. For each test case, the first line contains a single positive integer N indicates the times you can guess,the following N Lines is the record of the ' Guess ' in the form:

# # # # #A #b

The first four numbers are the numbers guessed,then the judgements for your guess. The input is terminated by a negative integer.

Output

For each test case, the output a single line contains exactly four digits that the computer have chosen. You could assume that all test case gives you enough information and so can figure out the correct answer.

Sample input

21234 2a4b1243 0a4b30732 3a3b1526 0a0b4567 0a2b-1

Sample output

21340734


#include <iostream> #include <stdio.h> #include <string> #include <cstring> #include <cmath  > #define N 19using namespace Std;int s[n],aa[n],bb[n],a[n];int n;int check (int ans) {for (int k=0;k<n;k++) {int    cnt=3;    int ss[4];    int X=ans;        for (int i=0;i<4;i++) {ss[cnt]=x%10;        x/=10;    cnt--;    } if (Ss[0]==ss[1] | | ss[0]==ss[2] | | ss[0]==ss[3] | | ss[1]==ss[2] | | ss[1]==ss[3] | | ss[2]==ss[3]) return 0;    int tt[4];    cnt=3;    X=A[K];        for (int i=0;i<4;i++) {tt[cnt--]=x%10;    x/=10;    } int num=0;        for (int i=0;i<4;i++) {if (Tt[i]==ss[i]) {num++;    }} if (Num!=aa[k]) return 0;    num=0;                for (int i=0;i<4;i++) {for (int j=0;j<4;j++) {if (Tt[i]==ss[j]) {                num++;            Ss[j]=-1;    }}} if (Num!=bb[k]) return 0; } return 1;} int main () {while (~SCANF ("%d",&N) {if (n<0) break;       char x, y;           for (int i=0;i<n;i++) {scanf ("%d", &a[i]);       scanf ("%d%c%d%c", &aa[i],&x,&bb[i],&y);       } int ans=0;                for (int i=0;i<9999;i++) {if (check (i)) {ans=i;           Break    }} printf ("%04d\n", ans); } return 0;}




Hnu number guessing

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.