首页 > 代码库 > 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节练习
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。