DWITE Online Computer Programming Contest

Costume Party

October 2012
Problem 3

Alice wants to hold a costume party for this Halloween. To make things interesting and prevent potential fights, she decided to make sure that all her friends will dress up in different costumes for the party. How she does this is by calling her friends one by one and asking them what they were planning on wearing for the party. If they were planning to wear a costume that someone Alice has already spoken to was planning to wear, then Alice tells them to wear something else. Being her best friend, she asks you to keep track of the friends she asks to wear something else (in case they need a reminder later on).

The input file DATA3.txt will contain 5 test cases. Each test case will start with a number 1 ≤ N ≤ 20, the number of friends Alice will call, followed by N lines – each having a pair of words, which are the friend’s name and their costume (each without spaces).

The output file OUT3.txt will contain 5 lines: Lists of friends that were asked to change costumes, in the order that they were called. Each list will be a single line with names separated by spaces. If a list is empty, print SPOOKY instead.

Note: Since the judge checks if your line is an exact match, make sure not to end the list with an extra space. That is, the first sample is “jim sam”, not “jim sam ”.

Sample Input (first 2 shown):
4
bob casper
carrie scooby
jim casper
sam casper
3
tommy mummy
billy reaper
jim casper
Sample Output (first 2 shown):
jim sam
SPOOKY