2001 Canadian Computing Competition, Stage 2

Day 1, Problem 2: Coke or Chocolate Milk

Anybody who has been to a child's birthday has seen the following scenario:

  • Parent: OK Kids, what do you want to drink, Coke or Chocolate Milk?
  • Jamie: Coke
  • John: I hate Coke
  • Mary: I want what John is having
  • Barry: Ick! Then I don't want it if she's going to have it
  • ... etc.
This is a large party. 1000 people have been invited and nearly that number may show up. Can you make everybody happy?

Input

The input may contain several test cases. The first line of each test case is an integer N, the number of requests that must be satisfied. Following this line are the N requests, each on its own line. Each request has one of these formats:
<person> wants <drink>
<person> hates <drink>
<person> wants same as <person>
<person> wants different from <person>
<person> wants <drink> if <person> gets <drink>
<person> is the name of a person - up to 20 lower-case letters. <drink> is either Coke or chocolate milk.

Output

If it is possible to make everybody happy, print one line per person, in alphabetical order, with the format
<person> gets <drink>
Be sure to correctly capitalize the drinks (Coke, chocolate milk).

If there is more than one way to make everybody happy (fat chance!), fill their glasses in alphabetical order and pour Coke (it's cheaper) whenever there is a choice. If it is not possible to make everybody happy, print

Everybody gets water
Output a blank line after each test case. The input ends with 0 for the value of N.

Sample Input

4
jamie wants Coke
john hates Coke
mary wants same as john
barry wants different from mary
0

Sample Output

barry gets Coke
jamie gets Coke
john gets chocolate milk
mary gets chocolate milk

All Submissions
Best Solutions


Point Value: 20
Time Limit: 2.00s
Memory Limit: 16M
Added: Apr 18, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Supposing Coke = 1 & Chocolate Milk = 0, does "Alice wants Coke if Bob gets Coke" mean B → A?

Yeah, I think it's pretty clear - if Bob gets Coke, then Alice has to get Coke. If Bob gets Chocolate Milk, then Alice can get anything.