cho.sh
Notes
Loading...

Bus Timetable

Time limit

1s

Memory limit

128 MB

Problem

A bus timetable has stop numbers down the left side and service columns to the right. Each service column is labeled with the route number for that service. A cell is either blank or contains the time when that service leaves that stop.

Given the route and service details for several scenarios, write a program that prints the corresponding bus timetable for each scenario.

Input

The input contains several scenarios. Each scenario begins with one title line, followed by one line for each route in that scenario. The entire input ends with a line containing only #.

A route line starts with the hour and minute when the first service leaves the depot, followed by the interval between services in minutes. After that come pairs of integers: a travel time and the bus stop reached after that travel time. The route list for one scenario ends with a line containing 0 0.

Routes are numbered implicitly from 1 in input order. Bus stops are also numbered from 1. Except for the final return to the depot, buses visit stops in increasing stop-number order. The depot is treated as stop 0, so the last stop number in every route description is always 0. A scenario contains at most 10 routes and at most 99 stops. No bus leaves before 6:00, and every generated service must return to the depot by midnight. Do not output a service that violates that condition.

Output

Print one timetable for each scenario. The first line of a timetable is the scenario title exactly as given. The next line is the service header: list each generated service's route number, sorted by its departure time from the depot. Then print one line for each stop number that appears in the input.

Each stop line starts with the stop number in a field of width 2. Each service cell has width 6 and starts with |. If the service does not stop there, the remaining five characters are spaces. If it does stop there, the remaining five characters contain the departure time in 24-hour hh:mm format, with leading zeroes when needed. Each line also ends with |. Times increase as you move downward within one service column, but they do not necessarily increase from left to right within a row. Print one blank line between consecutive scenarios.