STL交集,并集函数set_union,set_intersection,set_difference

//#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <queue>
#include <vector>
#include <iterator>
#include <map>
#include <bitset>
#include <stack>
#include <deque>
#include <cmath>
#include <iomanip>
#include <forward_list>
#include <set>
#include <cmath>
#include <cctype>
#include <sstream>
#include <climits>
#include <list>
#include <typeinfo>
//INT_MAX 32 bit int
//LLONG_MAX 64 bit int
//LONG_MAX 64 bit int

using namespace std;

//#pragma comment(linker, "/STACK:3073741824")
#define memmin(a) memset(a,0,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a));
#define spr(n) fixed << setprecision(n)
#define endll '\n'
#define ifor(i, l, r) for (long long (i) = (l); (i) <= (r); ++(i))
#define rfor(i, r, l) for (long long (i) = (r); (i) >= (l); --(i))
#define fori(i,l,r) for(auto i=p;i!=p1;++i)
#define rfori(i,rl,rr) for(auto i=rl;i!=rr;++i)
#define coute cout<<'\n'
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

template <class T, class Container = vector<T>,
          class Compare = less<typename Container::value_type> >
using priqueue = priority_queue<T,Container,Compare>;

#define start1
#ifndef start1
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1.0e-9;
const long long MOD = 1e9 + 7;
const int MAX1 = 1e5 + 100;
const int MAX2 = 1e7 + 100;

#endif

#define start2
#ifndef start2

//__int128读取
void  read(ll& w) {
	w=0;
	ll f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		w = w * 10 + ch - '0';
		ch = getchar();
	}
}

void print128(ll x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)print128(x / 10);
	putchar(x % 10 + '0');
}

#endif

#define start
#ifndef start3
template<typename container>
void _print(container &a2) {
	for (auto i = a2.begin(); i != a2.end(); i++) {
		if (i == a2.begin()) cout << *i;
		else
			cout << " " << *i;
	}
}

template<typename T1>
auto _print(T1 a1, ll l, ll r) ->void {
	for (ll i = l; i <= r; ++i) {
		if (i == l) cout << a1[i];
		else cout << " " << a1[i];
	}
}
#endif

int main(int argv,char** argc) {
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	list<int>das1 {56,4,3,89,12,3,66};
	list<int> das2 {4,89,45,63,56,7,6};
	list<int>das3;
	das3.resize(12);
	auto p=set_union(das1.begin(),das1.end(),das2.begin(),das2.end(),
	                 back_inserter(das3));
	_print(das3);
	cout<<endl;
//insert_iterartor<typenmae> name()
	list<int>das4;
	insert_iterator<list<int>> it(das4,das4.begin());
	auto p1=set_intersection(das1.begin(),das1.end(),das2.begin(),das2.end(),it);
	_print(das4);
	cout<<endl;
//front_inserter()
	list<int> das5;
	set_difference(das1.begin(),das1.end(),das2.begin(),das2.end(),
	               front_inserter(das5));
	_print(das5);
	cout<<endl;

//inserter(constainer &a,constainer::iterator it);
	list<int> das6;
	set_difference(das1.begin(),das1.end(),das2.begin(),das2.end(),
	               inserter(das6,das6.begin()));
	_print(das6);

	return 0;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务