119.cpp
来自「学习C++ Primer中文版第四版时」· C++ 代码 · 共 75 行
CPP
75 行
#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 + =
减小字号Ctrl + -
显示快捷键?