commit 344e59315e888689ab8ecde5a22f0b24fb936c3d
parent 9516fefe56c16201672ae03ddc5a6eada9d3859b
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 31 May 2023 15:33:34 +0200
Daily Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/1396.cpp b/Problems/1396.cpp
@@ -0,0 +1,23 @@
+class UndergroundSystem {
+ unordered_map<int, pair<string, int>> check_in;
+ unordered_map<string, pair<int, int>> average;
+
+public:
+ UndergroundSystem() {}
+
+ void checkIn(int id, const string &stationName, int t) {
+ check_in[id] = {stationName, t};
+ }
+
+ void checkOut(int id, const string &stationName, int t) {
+ auto &[name, time] = check_in[id];
+ auto &p = average[name + "-" + stationName];
+ p.second += t - time;
+ p.first++;
+ }
+
+ double getAverageTime(const string &startStation, const string &endStation) {
+ auto &p = average[startStation + "-" + endStation];
+ return (double)p.second / p.first;
+ }
+};
diff --git a/README.md b/README.md
@@ -566,3 +566,4 @@ for solving problems.
| 2666 | Easy | [Allow One Function Call](Problems/2666.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |
| 2676 | Medium | [Throttle](Problems/2676.js) |
+| 1396 | Medium | [Design Underground System](Problems/1396.cpp) |