Problem
The magician arranges 16 cards from one to sixteen in a square grid
(4x4). Next, the magician asks a volunteer to choose a card, and tell him which
in the four rows the card in located.
The
magician then shuffles the cards and arranges them in a similar square grid.
Now the card position have been changed. Again, he asks the volunteer which row
his card is located. After the row is located, the magician now announces the
card that the volunteer chose.
Write a program
that will do the above-mentioned magic. The input file will be given the 2 4x4
arrangement of cards, and the volunteer's chosen row: the row number of the
selected card in the first arrangement, and the row number of the selected card
in the second arrangement. The rows are numbered 1 to 4 from top to bottom.
Solving this problem
Input (input.in)
The trick has
three parts. Line 1, which contains a single integer. This represents the number
on how many times it was done (T). The subsequent parts will be a pattern of 1
integer (R) and 4 lines of integers from 1-16. R will represent the row that
the person chose, while the next four lines will be the arrangement of the
cards.
Output (web browser or text file)
For every time the magic was done (T). The output will be “Case #T:X”
Theoretically, the program should get the integer/card that the volunteer
chose. The value of X will depend on how many result does the program have:
1.
If X==1, meaning there is a single card that he
chose, X must be equal to the value of the number chosen;
2.
If X>1, meaning there are
multiple identical cards in the chosen rows, X must be “Magic Failed!”;
3.
If X <= 0, meaning there are
no cards similar in the two card arraignment, X must be “Cheater!”
Sample Input
3
2
2 1 4 3
6 8 7 5
9 12 11 10
14 13 16 15
3
4 5 2 1
11 3 15 6
12 7 10 9
14 13 16 8
2
4 3 2 1
8 7 6 5
12 11 10 9
14 13 16 15
2
1 4 2 3
6 8 7 5
12 11 9 10
13 14 15 16
2
4 2 1 3
7 5 6 8
9 11 12 10
16 15 13 14
3
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
|
Sample Output
Case #1: 7
Case #2: Magic Failed!
Case #3: Cheater!
|
