Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bulls and Cows You are required to play a game of Bulls and Cows, with a computer. The game is a word-game, and proceeds as

Bulls and Cows

You are required to play a game of Bulls and Cows, with a computer. The game is a word-game, and proceeds as follows

  • The computer 'thinks' of a four-letter word consisting of letters A to D
  • Then it proceeds to give you several clues, as to what the word is
  • Given the clues, you have to work-out the word that the computer thought of (secret-word)

The computer, keeping in mind our agrarian roots, gives clues in the form of 'bulls' and 'cows'! Given a guess-word, it tells us the number of 'bulls' and 'cows' in the word. A 'bull' stands for a letter which is in it's correct place in the secret-word, and a 'cow' stands for a letter which is present in the secret-word, but not in the correct place. However, to make the game a bit challenging, the computer does not tell us which letter is a bull and which one is a cow! Bulls are counted first and then cows. Additionally, each letter in the secret-word is counted only once.

For example, if the computer thought of the word: BDAA and the guess-word is: ADDA, then the computer would respond as 2 bulls and 1 cow. This is so, because the letters 'A' and 'D' in the clue word are present in their correct places (with regard to BDAA) and hence 2 bulls. The other 'A' in the guess-word is present in the wrong place (with regard to BDAA) and hence 1 cow.

Given several such clue words and the number of cows and bulls for each word, your program should be able to work out the actual word that the computer had thought of.

NOTE: It is guaranteed that the clues will be enough to work out the secret-word uniquely

Input Format

  • First line contains one integer N indicating the number of clue words which follow
  • The next N lines contain input of the form: W B C

Where 'W' is a string specifying the clue word, B is an integer specifying the number of bulls and C is an integer specifying the number of cows

Constraints

1<= N <=10

0<= B, C <=|W|

Output Format

A string which is the word that the computer thought of, i.e., secret-word.

Sample TestCase 1

Input

4DBCC02

CDAB21

CAAD12

CDDA20

Output

BDAA

java code solution for this problem?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions