-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path16.cpp
54 lines (41 loc) · 1.22 KB
/
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
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void print(vector<string> v) {
for(auto i : v) {
cout << i << " ";
}
cout << endl;
cout << "------------" << endl;
}
void elimDups(vector<string> &words){
sort(words.begin(), words.end());
auto end_unique = unique(words.begin(), words.end());
words.erase(end_unique, words.end());
}
string make_plural(size_t size, const string &word, const string &s){
auto words = size > 1 ? word + s : word;
return words;
}
void biggies(vector<string> &words, size_t sz) {
print(words);
elimDups(words);
print(words);
stable_sort(words.begin(), words.end(),
[](const string &s1, const string &s2) { return s1.size() < s2.size(); });
print(words);
auto wc = find_if(words.begin(), words.end(),
[sz] (const string &s) { return s.size() >= sz; });
auto count = words.end() - wc;
cout << count << " " << make_plural(count, "word", "s") << " of length " << sz << " or longer " << endl;
for_each(wc, words.end(),
[](const string &s) { cout << s << endl; });
print(words);
}
int main(){
size_t sz = 5;
vector<string> words = {"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "aed", "turtle"};
biggies(words, sz);
}