Design Underground System
pupil · 500 · lc medium +27 · 74.4% accepted · 3,586 likes · top 85%
Description
A subway system tracks trip times between stations to compute averages. Implement the UndergroundSystem class:
- void checkIn(int id, string stationName, int t)
- Customer id enters stationName at time t. Each customer can be checked in at only one station at a time.
- void checkOut(int id, string stationName, int t)
- Customer id exits stationName at time t.
- double getAverageTime(string startStation, string endStation)
- Returns the mean travel time over all completed direct journeys from startStation to endStation.
- The average covers only direct trips (check-in at start, check-out at end).
- Travel time from A to B may differ from B to A.
- At least one journey from startStation to endStation will exist before this is called.
All checkIn and checkOut calls are consistent (t1 < t2) and arrive in chronological order.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Example 6:
Code