http://acm.hdu.edu.cn/showproblem.php?pid=1172
Gameboy guessing game is one of the most favorite games. Rules of the game is this: a computer randomly generated four-digit number, then the player to guess what the four-digit yes. Each guess a number, the computer will tell the player guessed a few numbers, several numbers in the correct position.
Such as a digital computer 1122 is randomly generated. If the player to guess 1234, because these two figures 1 and 2 exist in both the number and the position of these two numbers are the same, the computer will tell the player to guess the numbers 2, wherein a in the correct position. If the player guessed 1111, the computer will tell him guessed two numbers, there are two in the correct position.
Now give you some gameboy process of dialogue with the computer, your task is to determine what this dialogue according to the four-digit yes.
Such as a digital computer 1122 is randomly generated. If the player to guess 1234, because these two figures 1 and 2 exist in both the number and the position of these two numbers are the same, the computer will tell the player to guess the numbers 2, wherein a in the correct position. If the player guessed 1111, the computer will tell him guessed two numbers, there are two in the correct position.
Now give you some gameboy process of dialogue with the computer, your task is to determine what this dialogue according to the four-digit yes.
Input
Multiple sets of input data. The first line of each a positive integer N (1 <= N <= 100), Q represents a total of N times in this conversation. In the next N rows, each row three integers A, B, C. gameboy guess digit of A, then the computer B answers guessed numbers, wherein C at a correct position. When N = 0, the input data is completed.
Output
Each set of input data corresponding to one line of output. If this dialogue can be determined according to the four-digit number, then the output of this four-digit number, if not, then output "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
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int N = 110; 8 struct Arr{ 9 int a,b,c; 10 }arr[N]; 11 int hashA[N],hashB[N]; 12 bool judge(int y,int n) 13 { 14 memset(hashA,0,sizeof(hashA)); // initialize an array Hasha 15 int A1, Bl, a C1, Dl, A2, B2, C2, D2 of; 16 A1% = Y 10 ; Hasha [A1] ++ ; // bit . 17 Bl = Y / 10 % 10 ; Hasha [Bl] ++ ; // ten 18 is a C1 = Y / 100 % 10 ; Hasha [a C1] ++ ; // one hundred . 19 Dl = Y / 1000 % 10 ; Hasha [Dl] + + ; // one thousand 20 is for ( int I = 0 ; I <n; I ++ ) // number n is determined keyboard input 21 is { 22 is Memset (hashB,0 , the sizeof (hashB)); // initialize an array hashB 23 is int X = ARR [I] II.A; 24 A2% X = 10 ; hashB [A2] ++ ; 25 B2 = X / 10 % 10 ; hashB [B2 ] ++ ; 26 is C2 = X / 100 % 10 ; hashB [C2] ++ ; 27 D2 of = X / 1000 % 10 ; hashB [D2 of] ++ ; 28 int CNT1 = 0 , CNT2 = 0 ; // record CNT1 the right number at the right position on the 29 IF (A1 == A2) CNT1 ++; 30 IF (== Bl B2) CNT1 ++ ; 31 is IF (a C1 == C2) CNT1 ++ ; 32 IF (Dl D2 of ==) CNT1 ++ ; 33 is IF (CNT1 = ARR [I] .c!) Return to false ; 34 is for ( int Q = 0 ; Q < 10 ; Q ++) + CNT2 = min (Hasha [Q], hashB [Q]); // single digit number between 10 ~ 0 35 IF ! (CNT2 = ARR [I] .B ) return to false ; 36 } 37 [ return to true ; 38 is } 39 40 intmain () 41 is { 42 is int n; 43 is the while (~ Scanf ( " % D " , & n) && n) 44 is { 45 for ( int I = 0 ; I <n; I ++ ) // input n sets of data 46 is Scanf ( " % D% D% D " , & ARR [I] II.A, & ARR [I] .B, & ARR [I] .c); // number of inputs, number guess B, C in the correct position on a 47 int ANS = - . 1 ; 48 for ( int I = 1000 ; I < 9999 ; I ++ ) 49 { 50 IF (Judge (I, n-)) 51 is { 52 is IF (ANS = -! . 1 ) ANS = {0; BREAK ;} // second matching, matching end 53 is ANS = I; // first match successfully, continues to match the next number 54 is } 55 } 56 is IF the printf ((ANS!) " Not Sure \ n- " ); 57 is the else the printf ( " % D \ n- " , ANS); 58 } 59 return 0 ; 60 }