1396.cpp (673B)
1 class UndergroundSystem { 2 unordered_map<int, pair<string, int>> check_in; 3 unordered_map<string, pair<int, int>> average; 4 5 public: 6 UndergroundSystem() {} 7 8 void checkIn(int id, const string &stationName, int t) { check_in[id] = {stationName, t}; } 9 10 void checkOut(int id, const string &stationName, int t) { 11 auto &[name, time] = check_in[id]; 12 auto &p = average[name + "-" + stationName]; 13 p.second += t - time; 14 p.first++; 15 } 16 17 double getAverageTime(const string &startStation, const string &endStation) { 18 auto &p = average[startStation + "-" + endStation]; 19 return (double)p.second / p.first; 20 } 21 };