C++ Primer课后练习10.20,10.21

//课后练习10.20
#include
#include
#include
#include
#include
using namespace std;
void elimdups(vector & words)
{
	//按字典序排序
	sort(words.begin(), words.end());
	auto end_unique = unique(words.begin(), words.end());
	words.erase(end_unique, words.end());
}
void biggies(vector & words,
	vector::size_type sz)
{
	elimdups(words); //将word按字典序排序,删除重复单词
	stable_sort(words.begin(), words.end(),
		[](const string& s1, const string & s2){return s1.size() < s2.size(); });
	auto wc = count_if(words.begin(), words.end(),
		[sz](const string s){return s.size() >= sz; });
	cout << "there are " << wc << " words whose size is larger than 6" << endl;
	auto iter = words.end() - wc;
	for_each(iter, words.end(),
		[](const string & s){cout << s << endl; });
}
int main(void)

{vector words;string word;while (cin >> word){words.push_back(word);}biggies(words, 6);return 0;}/*********************************************************************/
 
  
 
  
//课后练习10.21
#include
using namespace std;
int main(void)
{
	int num = 20;
	auto result = [& num]()->bool{
		if (num>0){num--;return false;}
		else return true;
	};
	while (!result())
	{
		cout << num << endl;
	}
	cout << result() << endl;
}

 
  
 
  


你可能感兴趣的:(C++,PRIMER)