-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path811.cpp
More file actions
33 lines (31 loc) · 1.01 KB
/
811.cpp
File metadata and controls
33 lines (31 loc) · 1.01 KB
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
class Solution {
public:
void processing(string s, int num, unordered_map<string, int>& counts) {
counts[s] += num;
if (s.find('.') == string::npos) return;
int index = s.find('.');
string nextStr = s.substr(index + 1);
processing(nextStr, num, counts);
}
vector<string> subdomainVisits(vector<string>& cpdomains) {
unordered_map<string, int> counts;
for (auto& cpdomain : cpdomains) {
stringstream ss(cpdomain);
string token;
string domain;
int count;
int index = 0;
while (getline(ss, token, ' ')) {
if (index == 0) count = stoi(token);
else domain = token;
index++;
}
processing(domain, count, counts);
}
vector<string> res;
for (auto& element : counts) {
res.push_back(to_string(element.second) + " " + element.first);
}
return res;
}
};