-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathex38.cpp
41 lines (34 loc) · 796 Bytes
/
ex38.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
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
class CompareString
{
public:
CompareString(size_t n) : default_size(n) {};
bool operator()(const std::string &s) const
{
return default_size == s.size();
}
private:
size_t default_size;
};
int main()
{
std::ifstream ifs("../ch09_Sequential_Containers/letter.txt");
if (!ifs) return -1;
std::vector<std::string> vs;
for(std::string curr; ifs >> curr; vs.push_back(curr));
for(int i = 1, n = 0; i < 11; ++i)
{
for(auto iter = vs.begin(); iter != vs.end(); )
{
iter = std::find_if(iter+1, vs.end(), CompareString(i));
if(iter != vs.end()) ++n;
}
std::cout << "length:" << i << "," << n << std::endl;
n = 0;
}
return 0;
}