1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
   | class UndergroundSystem { public:          using pii = pair<string, int>;          unordered_map<int, pii> in;     map<pair<string,string>, int> a, b;          UndergroundSystem() {         in.clear();         a.clear();         b.clear();     }          void checkIn(int id, string stationName, int t) {         in[id] = {stationName, t};     }          void checkOut(int id, string stationName, int t) {         auto [ss, tt] = in[id];         int time = t-tt;         a[{ss,stationName}] ++;         b[{ss,stationName}] += time;     }          double getAverageTime(string s, string t) {         return (double)b[{s,t}]/a[{s,t}];     } };
  |