#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#define ALL(x) x,x+5
#define INS(x) x.begin()
using namespace std;
int f[5]={5,10,15,20,25};
int s[5]={50,40,30,20,10};
void put(){
for(int i=0;i<5;i++)
cout<<f[i]<<" ";
cout<<endl;
for(int i=0;i<5;i++)
cout<<s[i]<<" ";
cout<<endl;
}
int main(){
vector<int> v(10); //并不知道开多大的空间 最后可以用 v.resize(it-INS(v)); 收场
vector<int>::iterator it;
sort(f,f+5);
sort(s,s+5);
put(); //输出当前排好序的两个数组
//it=set_union(ALL(f),ALL(s),INS(v)); // 5 10 15 20 25 30 40 50 0 0
it=set_intersection(ALL(f),ALL(s),INS(v)); //10 20 0 0 0 0 0 0 0 0
v.resize(it-INS(v)); //改变v容器的大小
cout<<v.size()<<endl;
for(it=v.begin();it!=v.end();++it) cout<<*it<<" ";
cout<<endl;
return 0;
}
vector set_union() /set_intersection【集合合并/交集】
最新推荐文章于 2022-12-03 08:30:00 发布