HDU 1172 (violent question)

Source: Internet
Author: User

Judge from the 0000-9999 enumeration once. If only one number is satisfied, the output is not sure.

 

 

Guess number

Time Limit: 20000/10000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1617 accepted submission (s): 925

Problem description guess digital games are one of Gameboy's favorite games. The rules of the game are as follows: The computer randomly generates a four-digit number, and then the player guesses what the four-digit number is. Each time you guess a number, the computer will tell the player to guess a few numbers, and several of them are in the correct position.
For example, the random number generated by a computer is 1122. If a player guesses 1234, because the numbers 1 and 2 exist in both numbers, and the positions of 1 in the two numbers are the same, the computer will tell the player to guess the two numbers, one of them is in the correct position. If a player guesses 1111, the computer will tell him to guess two numbers, two in the correct position.
Now, let's give you a conversation between Gameboy and the computer. Your task is to determine what the four digits are based on this conversation.

 

There are multiple groups of input data. The first behavior in each group is a positive integer N (1 <=n <= 100), indicating that there are n questions and answers in this dialog. In the next n rows, each row has three integers A, B, and C. Gameboy guessed that the four-digit number is A, and then the computer answered the correct B number, where C is in the correct position. When n = 0, the input data ends.

 

Output: each group of input data corresponds to a row of output. If the four-digit number can be determined based on this dialog, the four-digit number is output. If not, the "not sure" is output ".

 

Sample input6
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 output3585
Not sure

 

Authorlwg
# Include <stdio. h> # Include < String . H> # Include <Iostream> Using   Namespace  STD;  Struct  Node {  Int STR [ 5  ];  Int  CNT, num;} G [  110  ];  Int Mark [10  ];  Int  Main (){  Int  N;  While (Scanf ( "  % D  " , & N )&& N ){  For ( Int I = 0 ; I <n; I ++ ){ Int  TMP; scanf (  "  % D  " ,& TMP );  For ( Int J = 3 ; J> = 0 ; J -- ) {G [I]. Str [J] = TMP % 10  ; TMP /= 10 ;} Scanf (  "  % D  " , & G [I]. CNT ,& G [I]. Num );}  Int Flag = 0  ;  Int Sum = 0  ;  Int Ans [ 5  ];  For (Int A = 0 ; A < 10 ; A ++ )  For ( Int B = 0 ; B < 10 ; B ++ )  For ( Int C = 0 ; C < 10 ; C ++ ) For ( Int D = 0 ; D < 10 ; D ++ ) {Flag = 0  ; Memset (mark,  0 , Sizeof  (Mark); Mark [A] ++; Mark [B] ++; Mark [c] ++ ; Mark [d] ++ ; Int Mark1 [ 10  ];  For ( Int I = 0 ; I <n; I ++ ){  For ( Int J = 0 ; J < 10 ; J ++ ) Mark1 [J] =Mark [J];  Int Tcnt = 0  ;  For ( Int J = 0 ; J < 4 ; J ++ ){  If (Mark1 [G [I]. Str [J]! = 0  ) {Tcnt ++; Mark1 [G [I]. Str [J] -- ;}}  If (Tcnt! = G [I]. CNT) {flag = 1  ;  Break  ;}}  If (Flag = 1 )Continue  ;;  Int Tcnt = 0  ;  For ( Int I = 0 ; I <n; I ++ ) {Tcnt = 0  ;  If (G [I]. Str [ 0 ] = A) tcnt ++;  If (G [I]. Str [ 1 ] = B) tcnt ++ ;  If (G [I]. Str [ 2 ] = C) tcnt ++ ;  If (G [I]. Str [ 3 ] = D) tcnt ++ ;  If (Tcnt! = G [I]. Num) {flag = 1  ;  Break  ;}}  If (Flag = 1 ) Continue  ; Sum ++ ; Ans [  0 ] = A; ans [ 1 ] = B; ans [ 2 ] = C; ans [ 3 ] = D ;}  If (Sum! = 1 ) Printf ( "  Not sure \ n  "  );  Else  {  Int TMP = 0  ;  For ( Int I = 0 ; I < 4 ; I ++ ) TMP = TMP * 10 + Ans [I]; printf (  "  % 04d \ n  "  , TMP );}}  Return   0  ;} 

 

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.