-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lab_solution_11.cpp
44 lines (36 loc) · 1.23 KB
/
Lab_solution_11.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename C>
void printContainer(const string comment, C const& container)
{
cout << comment << " = { ";
for(auto n: container)
{
cout << n << ",";
}
cout << "}; \n";
}
int main()
{
cout << "Create vector vNumbers " << endl;
vector<int> vNumbers {5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
printContainer("vNumbers",vNumbers);
cout << "1- Print max value of vNumbers" << endl;
auto max = max_element(vNumbers.begin(), vNumbers.end());
cout << "Max = " << *max << endl;
cout << "2- Print min value of vNumbers" << endl;
auto min = min_element(vNumbers.begin(), vNumbers.end());
cout << "Min = " << *min << endl;
cout << "3- Create vWords a vector of string containig 3 strings" << endl;
vector<string> vWords {"AB", "ABC", "ABCDE"};
cout << "4- Print the longest string using max_element()" << endl;
auto sMax = max_element(vWords.begin(), vWords.end(),
[](const std::string s1, const std::string s2) {
return s1.size() < s2.size();
});
cout << "Min = " << *sMax << endl;
return 0;
}