-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesignUndergroundSystem.cpp
More file actions
31 lines (26 loc) · 905 Bytes
/
DesignUndergroundSystem.cpp
File metadata and controls
31 lines (26 loc) · 905 Bytes
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
30
31
class UndergroundSystem {
private:
unordered_map<int,pair<string,int>>info;
unordered_map <string, pair<int,int>>ans;
public:
UndergroundSystem() {
}
void checkIn(int id, string stationName, int t) {
info[id]={stationName, t};
}
void checkOut(int id, string stationName, int t) {
auto &[time_, c_]=ans[info[id].first+" "+stationName];
time_+=(t-info[id].second);
c_++;
}
double getAverageTime(string startStation, string endStation) {
return (double)ans[startStation+" "+endStation].first/ans[startStation+" "+endStation].second;
}
};
/**
* Your UndergroundSystem object will be instantiated and called as such:
* UndergroundSystem* obj = new UndergroundSystem();
* obj->checkIn(id,stationName,t);
* obj->checkOut(id,stationName,t);
* double param_3 = obj->getAverageTime(startStation,endStation);
*/