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
| vector<string> solve (vector<string> names)
{
unordered_set<string> s;
unordered_map<string, int> mp;
vector<string>ans;
for(const auto& name: names){
auto it = mp.find(name);
if(it != mp.end()){
it->second++;
ans.push_back(name + ' ' + to_string (it->second));
}
else{
mp[name] = 1;
string t;
bool inserted = false;
for(auto c : name){
t += c;
auto p = s.insert(t);
if(!inserted && p.second){
inserted = true;
ans.push_back(t);
}
}
if(!inserted) ans.push_back(t);
}
}
return ans;
}
|
No comments:
Post a Comment