您的位置:首页 > 编程语言 > C语言/C++

C++ 对于输出小数的位数控制+C++对集合的操作(交、并、差)

2016-11-15 17:57 337 查看
//对于集合的操作函数有  交集set_intersection   并集set_union    差集set_difference
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
int i;

int m=5,n=5;
int a[]={0,2,4,6,8};
int b[]={0,1,2,3,4};

vector<int> v(m+n);
vector<int>::iterator it;
sort (a,a+m);
sort (b,b+n);
it =set_difference (a,a+m,b,b+n,v.begin());//差集 6 8
//        it =set_union(a,a+m,b,b+n,v.begin());//并集 0 1 2 3 4 6 8
//        it =set_intersection(a,a+m,b,b+n,v.begin());//交集 0 2 4
//        it=set_symmetric_difference(a,a+m,b,b+n,v.begin());//1 3 6 8

if(int(it-v.begin())==0)
cout<<endl;
else{
for(i=0;i<int(it-v.begin()-1);i++)
cout<<v[i]<<" "; cout<<v[i]; cout<<endl;
}
return 0;
}



//在C++中有很多的库函数等待我们去了解,这些库函数能为我们的程序提供更加简短的版面,也能够为我们节省更多的时间。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: