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 }

 

转载于:https://www.cnblogs.com/wuyinfenghappy/p/7358006.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值