首页 > 代码库 > C++primer 10.3.3节练习

C++primer 10.3.3节练习

练习10.20

 1 #include<iostream>
 2 #include<string>
 3 #include <iostream>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <list>
 8 using namespace std;
 9 
10 void elmDups(vector<string> &vec);
11 
12 bool isShorter(string str, string str1);
13 
14 bool divide(string s);
15 
16 void biggies(vector<string> &words, vector<string>::size_type sz);
17 
18 int main()
19 {
20     vector<string> words{ "the", "quick", "red", "fox", "jumps", "over","the", "slow","red","turtle" };
21     elmDups(words);
22     stable_sort(words.begin(), words.end(), isShorter);
23     auto c = count_if(words.begin(), words.end(), [](const string &s) { return s.size() >= 6; });
24     cout << c << endl;
25     system("pause");
26     return 0;
27 }
28 
29 void elmDups(vector<string>& vec)
30 {
31     sort(vec.begin(), vec.end());
32     auto it = unique(vec.begin(), vec.end());
33     vec.erase(it, vec.end());
34 }
35 
36 bool isShorter(string str, string str1)
37 {
38     return str.size() < str1.size() ? true : false;
39 }

练习10.21

1 void lamtest(int sz)
2 {
3     auto f = [&sz]()mutable ->bool { while (sz != 0) --sz;  return 1; };
4     cout << f() << endl;
5 }

 

C++primer 10.3.3节练习