-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexec4-16.cpp
More file actions
34 lines (31 loc) · 784 Bytes
/
exec4-16.cpp
File metadata and controls
34 lines (31 loc) · 784 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// find min, max and mode in a sequence of numbers
int main() {
vector<int> v;
int x;
while (cin >> x)
v.push_back(x);
if (v.empty()) {
cout << "empty sequence\n";
return 0;
}
sort(v.begin(), v.end());
int count = 1, mode_count = 1, mode = v[0];
for (int i = 1; i < v.size(); ++i)
if (v[i] != v[i - 1]) {
if (count > mode_count) {
mode = v[i - 1];
mode_count = count;
count = 1;
}
}
else
++count;
cout << "min=" << v[0] << endl
<< "max=" << v[v.size() - 1] << endl
<< "mode=" << mode << endl;
return 0;
}