-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.8.1.cc
88 lines (66 loc) · 1.62 KB
/
14.8.1.cc
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
class CheckString{
public:
CheckString(size_t n):sz(n){}
bool operator()(const string & s){
return s.size() == sz;
}
private:
size_t sz;
};
void test(){
ifstream in("14.8.1.cc");
istream_iterator<string> iin(in);
istream_iterator<string> eof;
vector<string> svec(iin, eof);
map<size_t, size_t> m;
// for(auto __first = iin; __first != eof; ++__first){
// for(int i = 1; i <= 10; ++i){
// if(CheckString(i)(*__first))
// ++m.insert({i, 0}).first->second;
// }
// }
for(int i = 1; i <= 10; ++i)
m.insert({i, 0}).first->second = count_if(svec.begin(), svec.end(), CheckString(i));
for(auto & p : m){
cout << p.first << ": ";
cout << p.second << endl;
}
}
class CheckString2{
public:
CheckString2(size_t n):
sz(n){}
bool operator()(const string & s){
return s.size() < sz;
}
private:
size_t sz;
};
void test2(){
ifstream in("14.8.1.cc");
istream_iterator<string> iin(in);
istream_iterator<string> eof;
vector<string> svec(iin, eof);
cout << "< 10: ";
cout << count_if(svec.begin(), svec.end(), CheckString2(10));
cout << endl;
cout << ">= 10: ";
cout << count_if(svec.begin(), svec.end(), [](const string & s)->bool{
return !CheckString2(10)(s);
});
cout << endl;
}
int main(int argc, char const *argv[])
{
test2();
return 0;
}