回答編集履歴
1
修正
answer
CHANGED
@@ -24,17 +24,11 @@
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
27
|
-
// map<string,int> -> vector<pair<int,string>
|
28
|
-
std::vector<std::pair<
|
27
|
+
std::vector<std::pair<string,int>> hist(words.begin(), words.end());
|
29
|
-
std::transform(words.begin(), words.end(), hist.begin(),
|
30
|
-
[](const auto& item) { return std::make_pair(item.second, item.first); });
|
31
|
-
// partial sort
|
32
28
|
std::partial_sort(hist.begin(), hist.begin()+10, hist.end(),
|
33
|
-
[](const auto& x, const auto& y) { return x.
|
29
|
+
[](const auto& x, const auto& y) { return x.second > y.second; });
|
34
|
-
// print
|
35
30
|
for_each(hist.begin(), hist.begin()+10,
|
36
|
-
[](const auto& item) { std::cout << item.
|
31
|
+
[](const auto& item) { std::cout << item.second << " : "
|
37
|
-
<< item.
|
32
|
+
<< item.first << std::endl; });
|
38
|
-
return 0;
|
39
33
|
}
|
40
34
|
```
|