-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum-trio-elements.cpp
More file actions
44 lines (35 loc) · 1.07 KB
/
maximum-trio-elements.cpp
File metadata and controls
44 lines (35 loc) · 1.07 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
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int list_element;
std::vector<int> list1;
std::cout << "Please enter the first element: ";
std::cin >> list_element;
list1.push_back(list_element);
while (list_element != 0) {
std::cout << "Please enter the other elements (0 to stop): ";
std::cin >> list_element;
list1.push_back(list_element);
}
std::vector<int> list2;
for (int element : list1) {
if (std::find(list2.begin(), list2.end(), element) == list2.end()) {
list2.push_back(element);
}
}
int n = list2.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (list2[j] < list2[j + 1]) {
int temp = list2[j];
list2[j] = list2[j + 1];
list2[j + 1] = temp;
}
}
}
std::cout << list2[0] << std::endl;
std::cout << list2[1] << std::endl;
std::cout << list2[2] << std::endl;
return 0;
}