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

//对于集合的操作函数有  交集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++中有很多的库函数等待我们去了解,这些库函数能为我们的程序提供更加简短的版面,也能够为我们节省更多的时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值