并集 set_union()
交集set_intersection()
补 set_difference()
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
set<int> a,b;
vector<int> c;
int n,m;
cin>>n>>m;
while(n--)
{
int x;
cin>>x;
a.insert(x);
}
while(m--)
{
int x;
cin>>x;
b.insert(x);
}
//并集
set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
for(int t:c)cout<<t<<" ";
cout<<endl;
c.clear();
//交集
set_intersection(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
for(int t:c)cout<<t<<" ";
cout<<endl;
c.clear();
//差集
set_difference(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
for(int t:c)cout<<t<<" ";
cout<<endl;
c.clear();
return 0;
}
演示结果