Thinker, предложенный вариант также даёт частотный словарь всех слов в лексикографическом порядке))
Вот, кстати, полный код:
C++ |
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
| #include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
int main()
{
std::string text;
std::string str;
std::ifstream fin("input.txt");
while (std::getline(fin, str))
text += ' ' + str;
fin.close();
std::istringstream istr(text);
std::map< std::string, size_t > freq_dict;
std::string word;
while (istr >> word)
++freq_dict[word];
for (std::map< std::string, size_t >::const_iterator it = freq_dict.begin();
it != freq_dict.end();
++it)
std::cout << it->first << " : " << it->second << std::endl;
return 0;
} |
|