main168.cpp
#include
#include
#include
#include
#include
using namespace std;
//由题知道,键值唯一,可以知道,应该用set
static void output(string str)
{
cout<<str<<” “;
}
void main168()
{
set
set
string temp;
cout<<”Mat ,plesase enter your friends name(q to quit):”;
cin>>temp;
while(temp!=”q”)
{
Mat.insert(Mat.begin(),temp);
cout<<”\nMat ,plesase enter your friends name continue(q to quit):”;
cin>>temp;
}
cout<<”Mat’s friend list: “;
for_each(Mat.begin(),Mat.end(),output);
cout<<”\nNow ,Pat ,please enter your friend’s name:”;
cin>>temp;
while(temp!=”q”)
{
Pat.insert(Pat.begin(),temp);
cout<<”\nPat ,plesase enter your friends name continue(q to quit):”;
cin>>temp;
}
cout<<”\nPat’s friend list: “;
for_each(Pat.begin(),Pat.end(),output);
set
//transform(Mat.begin(),Mat.end(),All.begin(),[](set
//set_union(Mat.begin(),Mat.end(),Pat.begin(),Pat.end(),All.begin());//用set_union
set_union(Mat.begin(),Mat.end(),Pat.begin(),Pat.end(),insert_iterator<set
cout<<”\nAll list:”;
for_each(All.begin(),All.end(),output);
cin.get();
cin.get();
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案168/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!