-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_18.cpp
39 lines (30 loc) · 1021 Bytes
/
10_18.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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
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 ctr, const string &word, const string &ending = "s")
{
return (ctr > 1) ? word + ending : word;
}
void biggies(vector<string> & words, vector<string>::size_type sz)
{
elimDups(words);
auto wc = partition(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 << " "; });
cout << endl;
}
int main()
{
vector<string> vec{"A", "dog", "is", "running", "super", "fucking", "fast","amazing"};
biggies(vec, 5);
return 0;
}