-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe17.cpp
60 lines (49 loc) · 1.08 KB
/
e17.cpp
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
53
54
55
56
57
58
59
60
#include "../std_lib_facilities.h"
int main ()
{
vector<string> words = {
"paint",
"chair",
"talented",
"integrity",
"name",
"pace",
"thought",
"civilization",
"deep",
"stain",
"solid",
"visual",
};
vector<string> v;
for (int i = 0 ; i <= 100 ; ++i)
{
v.push_back(words[rand() % words.size() ]);
}
string min_string = *min_element(v.begin(), v.end());
string max_string = *max_element(v.begin(), v.end());
vector<int> frequency(words.size());
for (const auto& word: v)
{
auto it = find(words.begin(), words.end(), word);
auto index = distance(words.begin(),it);
frequency[index]++;
}
for (int i = 0; i != words.size(); ++i)
{
cout << frequency[i] << "\t\t" << words[i] << endl;
}
int max_freq = *max_element(frequency.begin(), frequency.end());
string mode;
for (int i = 0 ; i < frequency.size() ; ++i)
{
if (frequency[i] == max_freq)
{
mode = words[i];
}
}
cout << endl;
cout << "Min:" << "\t\t" << min_string << endl;
cout << "Max:" << "\t\t" << max_string << endl;
cout << "Mode:" << "\t\t" << mode;
}