Magic Trick problem

From FRC Illawarra Wiki
Jump to: navigation, search

Here is our solution to a practice problem from Google Code Jam 2015.

test_cases = int(input())
 
for i in range (1, test_cases+1):
    row = int(input())
    for j in range(1, 5):
        line = input()
        if row == j:
                cardlist = line.strip().split(' ')
 
    row = int(input())
    for j in range(1, 5):
        line = input()
        if row == j:
                cardlist2 = line.strip().split(' ')
 
    matches = [card for card in cardlist if card in cardlist2]
 
    if len(matches) == 1:
        print("Case #" + str(i) + ": " + matches[0])
    elif len(matches) > 1:
        print("Case #" + str(i) + ": " + "Bad magician!")
    else:
        print("Case #" + str(i) + ": " + "Volunteer cheated!")