Under construction

Still being built. Things may change

A Day at the Races

Time limit1sMemory limit128 MB

Summary
Read a season of Grand Prix results and print final standings for drivers and teams, breaking ties by countback and then lexicographically.
Level

Medium4 of 10

Topics
Simulation, Sorting, Hash map, Implementation
Solved
No attempts yet

Problem

Formula One is the top class of car racing. A season is a series of races called Grands Prix, in which constructors such as Ferrari and Renault enter one or more cars driven by some of the best drivers in the world. Throughout a season, teams compete in two parallel championships: the drivers' championship and the teams' championship.

In the drivers' championship, each driver tries to score as many points as possible over the season. In every Grand Prix the top eight drivers score 10, 8, 6, 5, 4, 3, 2, and 1 points, from first place to eighth. Drivers are ranked by total points, in decreasing order. When two drivers have the same total, the one with more first-place finishes ranks higher; if they are still tied, the one with more second-place finishes ranks higher, and so on down to eighth-place finishes. If two drivers are still tied after all of that, they are ordered lexicographically, first by last name and then by first name.

After each race, the points a driver scores are added to the pocket of the team the driver raced for. Sponsors may buy drivers from other teams even during the season, so a driver may race for different teams in different Grands Prix; the points always go to the team of that particular race. At the end of the season the team with the most points wins the teams' championship. When two teams have the same total, they are ordered lexicographically by name.

Given the results of one Formula One season, produce both the drivers' standings and the teams' standings.

Input

The input contains one or more data sets, each describing one Formula One season. Every input line is at most 255 characters long.

The first line of a season contains an integer NN with 0<N<320 < N < 32, the number of Grands Prix in that season. Each Grand Prix is given as follows:

  • One line with the name of the Grand Prix (at most 64 characters).
  • The table of the top eight finishers, positions 1 through 8. Each data row lists the finishing position, then the driver's first name, last name, and team name.
  • One line containing three dashes (---) marks the end of the Grand Prix.

First names and last names are sequences of printable ASCII characters, contain no spaces, and are at most 12 characters long. A team name is a sequence of printable ASCII characters, at most 18 characters long, and may contain spaces (but no leading or trailing spaces). Each team name is immediately followed by a single period (.), which is not part of the name; trailing whitespace may follow. A row that does not begin with a finishing position (for example, a column header) is not data and is ignored.

The input ends with a line containing a single 0.

Output

For each data set, print a line Season k:, where kk is the number of the data set, starting from 1. Then print a line Drivers Standing: followed by the drivers' standings, one driver per line: the first and last name separated by exactly one space, left-justified in a field of width 25, then a single space, then the driver's total points for the season.

Print a blank line, then a line Teams Standing: followed by the teams' standings, one team per line: the team name left-justified in a field of width 25, then a single space, then the team's total points for the season.

Separate consecutive data sets with a blank line. There is no additional blank line after the last data set.

Examples2

  1. Example 1

    Input
    2 
    FORMULA 1 Gran Premio Telefonica de Espana 2006
    Pos  Driver                    Team
    1    Fernando Alonso           Renault.
    2    Michael Schumacher        Ferrari.
    3    Giancarlo Fisichella      Renault.
    4    Felipe Massa              Ferrari.
    5    Kimi Raikkonen            McLaren-Mercedes.
    6    Jenson Button             Honda.
    7    Rubens Barrichello        Honda.
    8    Nick Heidfeld             Sauber-BMW.
    ---
    FORMULA 1 Grand Prix de Monaco 2006
    Pos  Driver                    Team
    1    Fernando Alonso           Renault.
    2    Jaun-Pablo Montoya        McLaren-Mercedes.
    3    David Coulthard           RBR-Ferrari.
    4    Rubens Barrichello        Honda.
    5    Michael Schumacher        Ferrari.
    6    Giancarlo Fisichella      Renault.
    7    Nick Heidfeld             Sauber-BMW.
    8    Ralf Schumacher           Toyota.
    ---
    0
    
    Expected output
    Season 1:
    Drivers Standing:
    Fernando Alonso           20
    Michael Schumacher        12
    Giancarlo Fisichella      9
    Jaun-Pablo Montoya        8
    Rubens Barrichello        7
    David Coulthard           6
    Felipe Massa              5
    Kimi Raikkonen            4
    Jenson Button             3
    Nick Heidfeld             3
    Ralf Schumacher           1
    
    Teams Standing:
    Renault                   29
    Ferrari                   17
    McLaren-Mercedes          12
    Honda                     10
    RBR-Ferrari               6
    Sauber-BMW                3
    Toyota                    1
    
  2. Example 2

    Input
    1
    Simple Grand Prix
    1    Alice Anderson            Speed Racing.
    2    Bob Brown                 Thunder.
    3    Carol Clark               Speed Racing.
    4    Dave Davis                Lightning.
    5    Eve Evans                 Thunder.
    6    Frank Ford                Lightning.
    7    Grace Green               Storm.
    8    Henry Hall                Storm.
    ---
    0
    
    Expected output
    Season 1:
    Drivers Standing:
    Alice Anderson            10
    Bob Brown                 8
    Carol Clark               6
    Dave Davis                5
    Eve Evans                 4
    Frank Ford                3
    Grace Green               2
    Henry Hall                1
    
    Teams Standing:
    Speed Racing              16
    Thunder                   12
    Lightning                 8
    Storm                     3