forked from huangmingchuan/Cpp_Primer_Answers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise10_16.cpp
46 lines (37 loc) · 840 Bytes
/
exercise10_16.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void elimdups(std::vector<std::string> &vs)
{
std::sort(vs.begin(), vs.end());
auto new_end = std::unique(vs.begin(), vs.end());
vs.erase(new_end, vs.end());
}
void biggies(std::vector<std::string> &vs, std::size_t sz)
{
elimdups(vs);
std::stable_sort(vs.begin(), vs.end(),
[](string const& lhs, string const& rhs) {
return lhs.size() < rhs.size(); }
);
auto wc = std::find_if(vs.begin(), vs.end(),
[sz](string const& s) { return s.size() >= sz; }
);
std::for_each(wc, vs.end(),
[](const string &s) {
std::cout << s << " "; }
);
}
int main()
{
std::vector<std::string> v
{
"1234", "1234", "1234", "hi~", "alan", "alan", "cp"
};
std::cout << "ex10.16: ";
biggies(v, 3);
std::cout << std::endl;
return 0;
}