回答編集履歴
1
修正
test
CHANGED
@@ -1,63 +1 @@
|
|
1
|
-
```C++
|
2
|
-
|
3
|
-
#include <iostream>
|
4
|
-
|
5
|
-
#include <map>
|
6
|
-
|
7
|
-
#include <algorithm>
|
8
|
-
|
9
|
-
#include <vector>
|
10
|
-
|
11
|
-
#include <string>
|
12
|
-
|
13
|
-
#include <utility>
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
int main() {
|
18
|
-
|
19
|
-
using namespace std;
|
20
|
-
|
21
|
-
typedef pair<char,int> histo_t;
|
22
|
-
|
23
|
-
vector<histo_t> histogram;
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
string input = "tttttttssssmmmmmnnnnnkkkkkoooo";
|
28
|
-
|
29
|
-
for ( char ch : input ) {
|
30
|
-
|
31
|
-
auto pos = find_if(histogram.begin(), histogram.end(),
|
32
|
-
|
33
|
-
[ch](const histo_t& item) { return item.first == ch;});
|
34
|
-
|
35
|
-
if ( pos == histogram.end() ) {
|
36
|
-
|
37
|
-
histogram.emplace_back(ch,1);
|
38
|
-
|
39
|
-
} else {
|
40
|
-
|
41
|
-
|
1
|
+
ごめん書くとこ間違えた。削除します。
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
sort(histogram.begin(), histogram.end(),
|
50
|
-
|
51
|
-
[](const histo_t& a, const histo_t& b) {
|
52
|
-
|
53
|
-
return b.second < a.second || (!(a.second < b.second) && a.first < b.first); });
|
54
|
-
|
55
|
-
for ( const auto& item : histogram ) {
|
56
|
-
|
57
|
-
cout << item.first << ' ' << item.second << endl;
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
```
|