stl系列(10):求交集

STL算法中的set_intersection可以求两个集合的交集,代码示例如下:

#include <algorithm>
#include <vector>

using namespace std;
int main()
{
	vector<int> a,b;
	for(int i=0; i<100; i++)
	{
		a.push_back(i);
		b.push_back(i+20);
	}
	vector<int> c(100);
	vector<int>::iterator it = set_intersection(a.begin(), a.end(), b.begin(),b.end(),c.begin());
	c.resize(it-c.begin());

	int d;
	cin>>d;
	return 0;
}


猜你喜欢

转载自blog.csdn.net/xiaoshuying/article/details/44939533
今日推荐