-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication_logs.cpp
57 lines (49 loc) · 1.08 KB
/
Application_logs.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
55
56
57
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
vector<string> processLogs(vector<string> logs, int threshold) {
map<int, int> mp;
for(auto x: logs) {
int sp1 = -1, sp2 = -1;
for(int i = 0; i < x.size(); ++i) {
if(x[i] == ' ') {
if(sp1 == -1) sp1 = i;
else sp2 = i;
}
}
int from = stoi(x.substr(0, sp1));
int to = stoi(x.substr(sp1 + 1, sp2 - sp1 - 1));
// cout << from << " " << to << " " << endl;
// increse count for different users
if(to == from) {
mp[to]++;
}
else {
mp[to]++;
mp[from]++;
}
}
vector<string> ans;
for(auto x: mp) {
if(x.second >= threshold) {
ans.push_back(to_string(x.first));
}
}
return ans;
}
int main() {
int n, threshold;
cin >> n;
cin.ignore();
vector<string> logs(n);
for(int i = 0; i < n; ++i) {
string temp;
getline(cin, temp);
logs[i] = temp;
}
cin >> threshold;
vector<string> ans = processLogs(logs, threshold);
for(auto s: ans) cout << s << endl;
}