Programming contests

Magas szintű programozási nyelvek 1, egyéni verseny, 2015. április 12.

April 12, 2015 10:00 AM – April 12, 2015 3:00 PM

Formula 1

It's time for a new Formula 1 race, and the board of directors decided that it's also time for a new chronometer system. They bought all the ultramodern radar-laser-microwave sensors to install in the starting line but just realized the manufacturer didn't provide the software to rank the cars.

That's how you come to the game. The board of directors wants you to write a program that receives the time each pilot spent on their qualification lap and prints the starting grid for the race (i.e., the order in which the pilots must start the race). And they want it fast! I bet you can do it in the time of a pit stop!

(If you don't know the rules that make the starting grid in Formula 1, consider that the less time the pilot spends on the qualification lap the better, i.e., the closer he will start to the beginning of the grid).

Input Specification

The input contains several input sets. The description of each set is given below:

Each set starts with one integer N (1 ≤ N ≤ 100), the number of participant pilots in the race, in the first line. Then, N lines in the format “S : X min Y sec Z ms” will follow (quotes for clarity only). The value S represents the name of the pilot and consists of 1 to 20 letters. The integers X (0 ≤ X ≤ 59), Y (0 ≤ Y ≤ 59), and Z (0 ≤ Z ≤ 999) represent the number of minutes, seconds, and milliseconds, respectively, that the pilot spent on his qualification lap.

There is a blank line after each input set. The input is terminated by EOF.

Output Specification

For each input set, your program must produce the starting grid, i.e., the order in which the pilots must start the race, in the following format: For each row in the grid (a pair of cars that start the race side by side), print a line containing “Row R”, where R represents the row number starting from 1, followed by two other lines containing the names of the pilots (as they appear in the input) that start the race from that row (in order of classification). If a row contains only one pilot, just print one line after the row number. If there are two pilots with the same name in a test case, they are different pilots, and the output must contain both of them. If two or more pilots are tied in the classification time, sort them by their names (lexicographically, case-insensitive comparisons). Print a blank line after each test case.

Sample Input

  1. 3
  2. Schumacher : 1 min 23 sec 172 ms
  3. Barrichello : 2 min 12 sec 999 ms
  4. Senna : 0 min 55 sec 582 ms
  5. 4
  6. Schumacher : 1 min 23 sec 172 ms
  7. Barrichello : 2 min 12 sec 999 ms
  8. Senna : 0 min 55 sec 582 ms
  9. Fangio : 1 min 03 sec 000 ms
  10. 2
  11. BadPilot : 59 min 59 sec 999 ms
  12. ABadPilot : 59 min 59 sec 999 ms
download as text file

Output for Sample Input

  1. Row 1
  2. Senna
  3. Schumacher
  4. Row 2
  5. Barrichello
  6. Row 1
  7. Senna
  8. Fangio
  9. Row 2
  10. Schumacher
  11. Barrichello
  12. Row 1
  13. ABadPilot
  14. BadPilot
download as text file
University of Debrecen; Faculty of Informatics; v. 03/19/2018