CF63C.Bulls and Cows

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.

The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format " xx bulls yy cows". xx represents the number of digits in the experimental number that occupy the same positions as in the sought number. yy represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.

For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).

When the guesser is answered "4 bulls 0 cows", the game is over.

Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.

输入格式

The first input line contains an integer nn ( 1<=n<=101<=n<=10 ) which represents the number of already made guesses. Then follow nn lines in the form of " aia_{i} bib_{i} cic_{i} ", where aia_{i} is the ii -th experimental number, bib_{i} is the number of bulls, cic_{i} is the number of cows ( 1<=i<=n1<=i<=n , 0<=bi,ci,bi+ci<=40<=b_{i},c_{i},b_{i}+c_{i}<=4 ). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.

输出格式

If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.

输入输出样例

  • 输入#1

    2
    1263 1 2
    8103 2 1
    

    输出#1

    Need more data
  • 输入#2

    2
    1234 2 2
    1256 0 2
    

    输出#2

    2134
  • 输入#3

    2
    0123 1 1
    4567 1 2
    

    输出#3

    Incorrect data
首页