-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExer10_20.cpp
More file actions
36 lines (36 loc) · 1.02 KB
/
Exer10_20.cpp
File metadata and controls
36 lines (36 loc) · 1.02 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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstddef>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
using std::size_t;
string make_plural(size_t ctr, const string &word, const string &ending)
{
return (ctr > 1) ? word + ending : word;
}
vector<string>::size_type count_size(vector<string> &words, vector<string>::size_type sz)
{
auto count = count_if(words.begin(), words.end(),
[sz](const string& s){return s.size() > sz;});
return count;
}
int main()
{
vector<string> words = { "the", "quick", "red", "fox", "jump", "over", "the", "slow", "red", "turtle" };
string::size_type sz;
while(cin >> sz)
{
auto cnt = count_size(words, sz);
cout << cnt << " " << make_plural(cnt, "word", "s")
<< " longer than " << sz << endl;
for_each(words.begin(), words.end(),
[sz](const string& str){ if(str.size() > sz) cout << str << " ";});
cout << endl;
}
return 0;
}