Programming contests

DEIK Regionális Programozó Csapatverseny, gyakorló feladatsor

October 26, 2012, 8:00 PM – November 23, 2012, 12:00 AM

Football (aka Soccer)

Football is the most popular sport in the world (Americans insist to call it “soccer”, but we will call it “football”). As everyone knows, Brasil is the country that have most World Cup titles (five of them: 1958, 1962, 1970, 1994, and 2002). As our national tournament have many teams (and even regional tournaments have many teams also), it's a very hard task to keep track of standings with so many teams and games played!

So, your task is quite simple: write a program that receives the tournament name, team names, and games played, and outputs the tournament standings so far.

A team wins a game if it scores more goals than its opponent. Obviously, a team loses a game if it scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3 points for each win, 1 point for each tie, and 0 point for each loss.

Teams are ranked according to these rules (in this order):

  1. Most points earned.
  2. Most wins.
  3. Most goal difference (i.e., goals scored - goals against).
  4. Most goals scored.
  5. Less games played.
  6. Lexicographic order.

Input Specification

The first line of the input will be an integer N in a line alone (0 < N < 1000). Then N tournament descriptions will follow. Each one begins with the tournament name, on a single line. Tournament names can have any letter, digits, spaces, etc. Tournament names will have a length of at most 100. Then, in the next line, there will be a number T (1 < T ≤ 30), which stands for the number of teams participating in this tournament. Then T lines will follow, each one containing one team name. Team names may have any character with an ASCII code greater than or equal to 32 (space), except for the “#” and the “@” characters, which will never appear in team names. No team name will have more than 30 characters.

Following the team names, there will be a non-negative integer G on a single line, which stands for the number of games already played in this tournament. G will be no greater than 1000. Then G lines will follow with the results of games played. They will follow this format:

team_name_1#goals1@goals2#team_name_2

For instance, the following line:

Team A#3@1#Team B

means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored 1. All goals will be non-negative integers less than 20. You may assume that there will not be inexistent team names (i.e., all team names that will appear in game results will have appeared on the team names section) and that no team will play against itself.

Output Specification

For each tournament, you must output the tournament name in a single line. In the next T lines, you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexicographic order, it must be done case insensitive. The output format for each line is shown below:

[a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])

where

  • [a] = team rank
  • [b] = total points earned
  • [c] = games played
  • [d] = wins
  • [e] = ties
  • [f] = losses
  • [g] = goal difference
  • [h] = goals scored
  • [i] = goals against

There must be a single blank space between fields and a single blank line between output sets. See the sample output for examples.

Sample Input

  1. 2
  2. World Cup 1998 - Group A
  3. 4
  4. Brazil
  5. Norway
  6. Morocco
  7. Scotland
  8. 6
  9. Brazil#2@1#Scotland
  10. Norway#2@2#Morocco
  11. Scotland#1@1#Norway
  12. Brazil#3@0#Morocco
  13. Morocco#3@0#Scotland
  14. Brazil#1@2#Norway
  15. Some strange tournament
  16. 5
  17. Team A
  18. Team B
  19. Team C
  20. Team D
  21. Team E
  22. 5
  23. Team A#1@1#Team B
  24. Team A#2@2#Team C
  25. Team A#0@0#Team D
  26. Team E#2@1#Team C
  27. Team E#1@2#Team D
download as text file

Output for Sample Input

  1. World Cup 1998 - Group A
  2. 1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
  3. 2) Norway 5p, 3g (1-2-0), 1gd (5-4)
  4. 3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
  5. 4) Scotland 1p, 3g (0-1-2), -4gd (2-6)
  6. Some strange tournament
  7. 1) Team D 4p, 2g (1-1-0), 1gd (2-1)
  8. 2) Team E 3p, 2g (1-0-1), 0gd (3-3)
  9. 3) Team A 3p, 3g (0-3-0), 0gd (3-3)
  10. 4) Team B 1p, 1g (0-1-0), 0gd (1-1)
  11. 5) Team C 1p, 2g (0-1-1), -1gd (3-4)
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024