slanted W3C logo

A Long Map Question (with Exception Handling)

Problem

Write a program that counts the number of gold, silver, and bronze medals won by each country in the Olympic Games. Your program should accept accept input from the keyboard until the user types the sentinel string "done" (alternatively, you can read from a file because the input is very long).

Assume that the input is line based, with the results for an event given as a comma-delimited list of fields:

men's curling, Canada, Finland, USA

where the first field is the event name, the second field is the gold medal winning country, the third field is the silver medal winning country, and the fourth field is the bronze medal winning country (note that this problem ignores the case where a tie has occurred). If a field is missing from the input, your program should print a warning message and ignore the line of input.

Your program should output the medal count for each country in order of the number of gold medals won. If there is tie for the number of gold medals won, the countries that tied should be listed in alphabetic order.

Sample Input: (based on the Turin 2006 Winter Olympics)

men's curling, Canada, Finland, USA
women's curling, Sweden, Switzerland, Canada
men's ice hockey, Sweden, Finland, Czech Republic
women's ice hockey, Canada, Sweden, USA
men's skeleton, Canada, Canada, Switzerland
women's skeleton, Switzerland, Great Britain, Canada
men's luge, Italy, Russia, Latvia
women's luge, Germany, Germany, Germany
mixed luge, Austria, Germany, Italy
men's 4 x 7.5 km relay biathlon, Germany, Russia, France
men's 12.5 km pursuit biathlon, France, Norway, Germany
men's 20 km individual biathlon, Germany, Norway, Norway
women's 4 x 6 km relay biathlon, Russia, Germany, France
women's 10 km pursuit biathlon, Germany, Germany, Russia
women's 15 km individual biathlon, Russia, Germany, Russia
men's halfpipe snowboarding, USA, USA, Finland
women's halfpipe snowboarding, USA, USA, Norway
some made up event, Canada, Bosnia and Herzegovina, Serbia and Montenegro
done

Sample Output:
Your program should output the country name using 25 spaces, and each number of medals using 3 spaces.

                   Canada  4  1  2
                  Germany  4  5  2
                   Russia  2  2  2
                   Sweden  2  1  0
                      USA  2  2  2
                  Austria  1  0  0
                   France  1  0  2
                    Italy  1  0  1
              Switzerland  1  1  1
   Bosnia and Herzegovina  0  1  0
           Czech Republic  0  0  1
                  Finland  0  2  1
            Great Britain  0  1  0
                   Latvia  0  0  1
                   Norway  0  2  2
    Serbia and Montenegro  0  0  1