-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharFrequencyUnicode.cpp
More file actions
52 lines (35 loc) · 1.1 KB
/
Copy pathCharFrequencyUnicode.cpp
File metadata and controls
52 lines (35 loc) · 1.1 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
map<wchar_t, int> freq(wstring text) {
map<wchar_t, int> letters;
int i = 0;
while(text[i]) {
if(text[i] != ' ') {
auto found = letters.find(text[i]);
if(found != letters.end()) {
found->second++;
} else {
letters.insert(pair<wchar_t, int>(text[i], 1));
}
}
i++;
}
return letters;
}
int main() {
setlocale(LC_ALL, "");
wcout<<"Text:"<<endl;
wstring text;
// reads a line for test, put in a while for text longer that 256 chars
getline(wcin, text);
wcout<<endl;
locale loc("");
transform(text.begin(), text.end(), text.begin(), ::toupper);
text.erase(remove_if(text.begin(), text.end(), ::isspace), text.end());
auto letters = freq(text);
for(auto it = letters.begin(); it != letters.end(); ++it) {
wcout<<it->first;
wcout<<" - "<<it->second<<endl;
}
return 0;
}