64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
void Show( vector<string> X);
int main()
{
vector<string> Mat;
vector<string> Pat;
string temp1;
string temp2;
cout<<"Mat, please enter your friends lists:";
while( getline(cin,temp1) )
{
Mat.push_back(temp1);
} //mat 的朋友名单
sort(Mat.begin(),Mat.end());
Show(Mat);
cout<<endl;
cout<<"Pat, please enter your friends lists:";
while(getline(cin,temp2))
{
Pat.push_back(temp2);
} //Pat 邀请的朋友名单
sort(Pat.begin(),Pat.end()); //对名单排序
Show(Pat); //显示名单
cout<<endl;
vector<string>::iterator p;
vector<string>::iterator q;
vector<string> Together; //两个人共有的名单
for(p=Mat.begin(); p!=Mat.end(); ++p)
Together.push_back(*p);
for(q=Pat.begin();q!=Pat.end();++q)
Together.push_back(*q);
// unique(Together.begin(),Together.end());
Show(Together);
system("pause");
return 0 ;
}
void Show(vector<string> X)
{
vector<string>::iterator q;
for(q=X.begin(); q!= X.end(); q++)
cout<<*q;
}
while( getline(cin,temp1) )
改成while( cin >> temp1 && temp1 != "quit" )