-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.cpp
54 lines (42 loc) · 1.11 KB
/
main.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
class Logger {
public:
Logger() {}
bool shouldPrintMessage(int timestamp, string message) {
if (m[message] > timestamp) {
return false;
}
m[message] = timestamp + 10;
return true;
}
private:
unordered_map<string, int> m;
};
int main() {
Logger logger;
// logging string "foo" at timestamp 1
cout << logger.shouldPrintMessage(1, "foo") << endl;
// logging string "bar" at timestamp 2
cout << logger.shouldPrintMessage(2,"bar") << endl;
// logging string "foo" at timestamp 3
cout << logger.shouldPrintMessage(3,"foo") << endl;
// logging string "bar" at timestamp 8
cout << logger.shouldPrintMessage(8,"bar") << endl;
// logging string "foo" at timestamp 10
cout << logger.shouldPrintMessage(10,"foo") << endl;
// logging string "foo" at timestamp 11
cout << logger.shouldPrintMessage(11,"foo") << endl;
return 0;
}