⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 119.cpp

📁 学习C++ Primer中文版第四版时
💻 CPP
字号:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

bool isShorter(const string &s1,const string &s2)
{
	return s1.size()<s2.size();
}
bool GT4(const string &s)
{
	return s.size() >=4;
}

void main()
{
	vector<string> words;
	string word;
	while(cin>>word){
		words.push_back(word);
	}

	sort(words.begin(),words.end());

	vector<string>::iterator it=words.begin();
	for(;it!=words.end();it++)
	{
		cout<<*it<<" ";
	}
	cout<<endl;

	vector<string>::iterator end_unique=unique(words.begin(),words.end());

	words.erase(end_unique,words.end());

	it=words.begin();
	for(;it!=words.end();it++)
	{
		cout<<*it<<" ";
	}
	cout<<endl;

	stable_sort(words.begin(),words.end(),isShorter);

	it=words.begin();
	for(;it!=words.end();it++)
	{
		cout<<*it<<" ";
	}
	cout<<endl;

	vector<string>::size_type wc=count_if(words.begin(),words.end(),GT4);
	cout<<wc<<" words:6 characters or longer"<<endl;

	it=find_if(words.begin(),words.end(),GT4);
	if(it!=words.end())
	{
		for(;it!=words.end();it++)
		{
			cout<<*it<<" ";
		}
	    cout<<endl;
	}


}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -