forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1396.cpp
More file actions
21 lines (19 loc) · 695 Bytes
/
1396.cpp
File metadata and controls
21 lines (19 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class UndergroundSystem {
public:
void checkIn(int id, string startStation, int timeIn) {
check_in[id] = {startStation, timeIn};
}
void checkOut(int id, string endStation, int timeOut) {
const auto &[startStation, timeIn] = check_in[id];
auto &[avg, cnt] = check_out[startStation + ">" + endStation];
avg += timeOut - timeIn;
++cnt;
}
double getAverageTime(string startStation, string endStation) {
auto [avg, cnt] = check_out[startStation + ">" + endStation];
return (double)avg / cnt;
}
private:
unordered_map<int, pair<string, int>> check_in;
unordered_map<string, pair<int, int>> check_out;
};