An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another.
Implement the UndergroundSystem
class:
check_in(id, station_name, time)
- A customer with a card
id
, checks in at the stationstation_name
at thetime
. A customer can only be checked into one place at a time.
- A customer with a card
check_out(id, station_name, time)
- A customer with a card
id
, checks out from the stationstation_name
at thetime
.
- A customer with a card
get_average_time(start_station, end_station)
- Returns the average time it takes to travel from
start_station
toend_station
.
- Returns the average time it takes to travel from
- The average time is computed from all the previous traveling times from
start_station
toend_station
that happened directly, meaning a check in atstart_station
followed by a check out fromend_station
. - The time it takes to travel from
start_station
toend_station
may be different from the time it takes to travel fromend_station
tostart_station
. - There will be at least one customer that has traveled from
start_station
toend_station
beforeget_average_time
is called. - You may assume all calls to the
check_in
andcheck_out
methods are consistent. - If a customer checks in at time t1 then checks out at time t2, then t1 < t2.
- All events happen in chronological order.
Commands file:
check<in/out>,id,station_name,time
get_average,start_station,end_station
Example
check_in,45,Leyton,3
check_in,32,Paradise,8
check_out,45,Waterloo,15
check_out,32,Cambridge,22
get_average,Paradise,Cambridge
Paradise,Cambridge,14.0
Input
check_in,45,Leyton,3
check_in,32,Paradise,8
check_in,27,Leyton,10
check_out,45,Waterloo,15
check_out,27,Waterloo,20
check_out,32,Cambridge,22
get_average,Paradise,Cambridge
get_average,Leyton,Waterloo
check_in,10,Leyton,24
get_average,Leyton,Waterloo
check_in,10,Waterloo,38
get_average,Leyton,Waterloo
Output
Paradise,Cambridge,14.0
Leyton,Waterloo,11.0
Leyton,Waterloo,12.0