Under construction

Still being built. Things may change

League Tables

Interview

Time limit2sMemory limit512 MB

Summary
Given each team's current record and a list of match results, update the records and print the table sorted by points, goal difference, goals scored, then name.
Level

Easy3 of 10

Topics
Implementation, Sorting, String, Simulation
Solved
No attempts yet

Problem

League football (also called soccer) has been played in England since 1888, and across most of Europe it is the most popular winter game, just as rugby is in New Zealand. English newspapers and many websites publish the latest results and the current table.

In the English league every team plays every other team both at home and away, and the team with the most points at the end of the season wins the title. A win is worth 3 points, and a draw is worth 1 point to each team. Teams level on points are separated by the larger goal difference, that is goals scored minus goals conceded. If the goal difference is level too, the team that has scored more goals is placed first.

You are given a list of teams with their current records, followed by a list of match results. Update the record of every team that has a result recorded, and print the table sorted by the rules below.

Input

The first line contains one integer TT (8≤T≤308 \le T \le 30), the number of teams in the league. The next 2×T2 \times T lines give the current record of each team, two lines per team, in this format:

<name>
<games played> <wins> <draws> <losses> <goals for> <goals against> <points>

The first line of a pair is the team name. A name is one or more words, may contain digits, uses only letters, digits and spaces, and is at most 30 characters long. The seven numbers on the second line are non-negative integers smaller than 150.

The next line contains one integer GG (0<G≤T/20 < G \le T/2), the number of recorded games. The next 4×G4 \times G lines give one game each, in this format:

<home team name>
<home team score>
<away team name>
<away team score>

Both teams appear in the list above. Each score is a non-negative integer smaller than 20.

Output

Print TT lines, one updated record per line. A line holds the team name, games played, wins, draws, losses, goals for, goals against and points in that order, separated by single spaces.

Update a record by adding the recorded results to it. The winner of a game adds 3 points to its previous total, and each team in a drawn game adds 1 point.

Sort the teams by points in descending order, then by goal difference in descending order, then by goals scored in descending order, then by team name in ascending order. Compare names after mapping uppercase letters to lowercase, one character at a time by ASCII code, so a space comes before a digit and a digit comes before a letter. Digits compare as characters and not as numbers, so "10 Bridges" comes before "9 Bridges".

Examples1

  1. Example 1

    Input
    18
    Aston Villa
    33 21 6 6 74 34 69
    Sheffield United
    34 18 12 4 63 33 66
    Sunderland
    33 18 3 12 47 34 57
    Wolverhampton Wanderers
    33 15 9 9 47 35 54
    Newcastle United
    34 13 10 11 53 43 49
    Manchester City
    33 13 8 12 49 41 47
    Nottingham Forest
    34 13 8 13 56 55 47
    Derby County
    33 13 8 12 43 42 47
    Stoke City
    34 13 8 13 37 45 47
    Everton
    33 13 7 13 46 30 46
    Bury
    33 13 6 14 40 57 45
    Liverpool
    33 13 5 15 47 45 44
    Blackburn Rovers
    33 12 4 17 47 60 40
    West Bromwich Albion
    34 11 8 15 43 51 41
    Preston North End
    33 12 4 17 37 45 40
    Notts County
    34 9 11 14 46 60 38
    Burnley
    34 11 5 18 34 54 38
    Glossop
    34 4 10 20 31 74 22
    5
    Aston Villa
    3
    Preston North End
    1
    Blackburn Rovers
    2
    Wolverhampton Wanderers
    1
    Derby County
    2
    Everton
    1
    Liverpool
    2
    Bury
    0
    Sunderland
    3
    Manchester City
    1
    
    Expected output
    Aston Villa 34 22 6 6 77 35 72
    Sheffield United 34 18 12 4 63 33 66
    Sunderland 34 19 3 12 50 35 60
    Wolverhampton Wanderers 34 15 9 10 48 37 54
    Derby County 34 14 8 12 45 43 50
    Newcastle United 34 13 10 11 53 43 49
    Manchester City 34 13 8 13 50 44 47
    Liverpool 34 14 5 15 49 45 47
    Nottingham Forest 34 13 8 13 56 55 47
    Stoke City 34 13 8 13 37 45 47
    Everton 34 13 7 14 47 32 46
    Bury 34 13 6 15 40 59 45
    Blackburn Rovers 34 13 4 17 49 61 43
    West Bromwich Albion 34 11 8 15 43 51 41
    Preston North End 34 12 4 18 38 48 40
    Notts County 34 9 11 14 46 60 38
    Burnley 34 11 5 18 34 54 38
    Glossop 34 4 10 20 31 74 22