回答編集履歴
1
修正
test
CHANGED
@@ -50,29 +50,17 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
// map<string,int> -> vector<pair<int,string>
|
54
|
-
|
55
|
-
std::vector<std::pair<
|
53
|
+
std::vector<std::pair<string,int>> hist(words.begin(), words.end());
|
56
|
-
|
57
|
-
std::transform(words.begin(), words.end(), hist.begin(),
|
58
|
-
|
59
|
-
[](const auto& item) { return std::make_pair(item.second, item.first); });
|
60
|
-
|
61
|
-
// partial sort
|
62
54
|
|
63
55
|
std::partial_sort(hist.begin(), hist.begin()+10, hist.end(),
|
64
56
|
|
65
|
-
[](const auto& x, const auto& y) { return x.
|
57
|
+
[](const auto& x, const auto& y) { return x.second > y.second; });
|
66
|
-
|
67
|
-
// print
|
68
58
|
|
69
59
|
for_each(hist.begin(), hist.begin()+10,
|
70
60
|
|
71
|
-
[](const auto& item) { std::cout << item.
|
61
|
+
[](const auto& item) { std::cout << item.second << " : "
|
72
62
|
|
73
|
-
<< item.s
|
63
|
+
<< item.first << std::endl; });
|
74
|
-
|
75
|
-
return 0;
|
76
64
|
|
77
65
|
}
|
78
66
|
|