Under construction

Still being built. Things may change

Soccer Tournament

Interview

Time limit1sMemory limit128 MB

Summary
Read team lists and played games, then print a result grid and a standings table sorted by points, goal difference, goals, wins, and reverse input order.
Level

Easy3 of 10

Topics
Implementation, Sorting
Solved
No attempts yet

Problem

A company decided to run a big advertising campaign. Among other things, it will sponsor soccer tournaments by providing a system that computes and displays game results. Write that system.

Input

The input describes several tournaments.

Each tournament begins with a line containing a single positive integer NN — the number of participating teams (N≤80N \le 80). The next NN lines each contain a unique team name. Names are case-sensitive and may contain only letters, digits, dots (.), and dashes (-). No name is longer than 100 characters.

After the team names comes a line with a single non-negative integer MM — the number of games already played. Each of the next MM lines describes one game in the format

host - guest r:r

that is, the host team name, a space, a dash, a space, the guest team name, a space, and the result. The result is a single digit (0-9), a colon (:), and another single digit (0-9), giving the goals scored by the host and by the guest respectively.

The tournaments follow one another. The last tournament is followed by a line containing a single 0, for which no output is produced.

Every team named in a game is guaranteed to appear among the NN listed teams. All games have distinct ordered (host, guest) pairs, so any two teams play at most two games with each other — once with each team as host.

Output

For each tournament print, in order:

  • a line containing the word RESULTS:,
  • the result table,
  • an empty line,
  • a line containing the word STANDINGS,
  • a line of exactly ten dashes (----------),
  • the current standings.

Print an empty line between consecutive tournaments, but not after the last one.

Result table. The table is drawn with dashes (-), pipes (|), and plus signs (+), and has N+1N + 1 rows and N+1N + 1 columns. The upper-left cell is empty (spaces). The first column holds the full team names; its width equals the length of the longest name. The first row holds the first three characters of each team name (padded with one or two spaces on the right when the name is shorter than three characters). Teams appear in the same order as in the input list.

Each diagonal cell (except in the first row and column) contains a centered uppercase X (a space, X, then a space). Every other inner cell is either empty (three spaces) or holds the result of the game already played, with the hosting team in the row and the guest team in the column.

Standings. The standings have one line per team, each with eight columns separated by a single space. Every column is right-aligned to the width of its widest entry, except the second column (team name), which is left-aligned. The columns are:

  1. The team's rank (starting at 1) followed by a dot (.).
  2. The team name.
  3. The number of games played.
  4. The number of games won (the team scored more goals than the opponent).
  5. The number of games tied (both teams scored the same).
  6. The number of games lost (the opponent scored more).
  7. The score: goals scored by the team, a colon (:), then goals scored against it, over all its games.
  8. The number of points: 3 for a win, 1 for a tie, 0 for a loss.

The standings are sorted by the following criteria, in order:

  1. Points — more points first.
  2. Goal difference (goals scored minus goals conceded) — higher first.
  3. Goals scored — more first.
  4. Games won — more first.
  5. Reverse input order — a team listed later in the input is ranked higher.

Examples1

  1. Example 1

    Input
    4
    Slavia
    Arsenal
    Steaua
    FCSevilla
    4
    Slavia - Arsenal 2:0
    FCSevilla - Steaua 1:1
    Steaua - Slavia 1:2
    Arsenal - Slavia 0:0
    0
    
    Expected output
    RESULTS:
    +---------+---+---+---+---+
    |         |Sla|Ars|Ste|FCS|
    +---------+---+---+---+---+
    |Slavia   | X |2:0|   |   |
    +---------+---+---+---+---+
    |Arsenal  |0:0| X |   |   |
    +---------+---+---+---+---+
    |Steaua   |1:2|   | X |   |
    +---------+---+---+---+---+
    |FCSevilla|   |   |1:1| X |
    +---------+---+---+---+---+
    
    STANDINGS
    ----------
    1. Slavia    3 2 1 0 4:1 7
    2. FCSevilla 1 0 1 0 1:1 1
    3. Steaua    2 0 1 1 2:3 1
    4. Arsenal   2 0 1 1 0:2 1