Write BusTimetable. Read n departures HH:MM line into a TreeMap<Integer, String> keyed by minutes after midnight. Print the first and last bus (firstKey, lastKey). Then, for each query time until the end of input, print:
- the next bus at or after that time (
ceilingEntry) with the waiting time, orno more buses today; - the bus just missed (
lowerEntry), ornone; - how many buses are left today (
tailMap(now, true).size()).
For the input
5
07:30 B12
08:15 B7
12:00 B12
17:45 B3
22:10 N1
08:00 08:15 23:00 06:00
the program prints
First bus: 07:30, last bus: 22:10
At 08:00:
next: 08:15 B7 (wait 15 min)
missed: 07:30 B12
buses left today: 4
At 08:15:
next: 08:15 B7 (wait 0 min)
missed: 07:30 B12
buses left today: 4
At 23:00:
next: no more buses today
missed: 22:10 N1
buses left today: 0
At 06:00:
next: 07:30 B12 (wait 90 min)
missed: none
buses left today: 5