64,654
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<iterator>
using namespace std;
int main(){
list<string> lst;
vector<string> svec;
string word;
cout<<"please enter the add words:"<<endl;
while(cin>>word){
lst.push_back(word);
}
cin.clear();
//sort(lst.begin(),lst.end());
unique_copy(lst.begin(),lst.end(),back_inserter(svec));
cout<<"the list words:"<<endl;
for(list<string>::iterator lit=lst.begin();lit!=lst.end();++lit){
cout<<*lit<<" ";
}
cout<<endl;
cout<<"the vector words:"<<endl;
for(vector<string>::iterator vit=svec.begin();vit!=svec.end();++vit){
cout<<*vit<<" ";
}
cout<<endl;
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<iterator>
using namespace std;
int main(){
list<string> lst;
vector<string> svec;
string word;
cout<<"please enter the add words:"<<endl;
while(cin>>word){
lst.push_back(word);
}
cin.clear();
cin.sync();
//sort(lst.begin(),lst.end());
lst.sort();
unique_copy(lst.begin(),lst.end(),back_inserter(svec));
cout<<"the list words:"<<endl;
for(list<string>::iterator lit=lst.begin();lit!=lst.end();++lit){
cout<<*lit<<" ";
}
cout<<endl;
cout<<"the vector words:"<<endl;
for(vector<string>::iterator vit=svec.begin();vit!=svec.end();++vit){
cout<<*vit<<" ";
}
cout<<endl;
return 0;
}