当前位置:网站首页>集合运算样例
集合运算样例
2022-08-09 22:07:00 【sichuanwww】
集合运算中的差集、交集、并集运算,set_difference,set_intersection、set_union
让人疑惑的是并不用集合,而是用向量计算。
// setSub.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> s1;
vector<int> s2;
vector<int> s3;
s1.push_back(1);
s1.push_back(2);
s2.push_back(1);
//差集
s3.resize(6,-1);
set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),s3.begin());
//删除-1
s3.erase(remove(s3.begin(),s3.end(),-1),s3.end());
copy(s3.begin(),s3.end(),ostream_iterator<int>(cout," "));
cout<<endl;
//交集
s3.resize(6,-1);
set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),s3.begin());
//删除0
s3.erase(remove(s3.begin(),s3.end(),-1),s3.end());
copy(s3.begin(),s3.end(),ostream_iterator<int>(cout," "));
cout<<endl;
//并集
s3.resize(6,-1);
set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),s3.begin());
//删除0
s3.erase(remove(s3.begin(),s3.end(),-1),s3.end());
copy(s3.begin(),s3.end(),ostream_iterator<int>(cout," "));
getchar();
return 0;
}
边栏推荐
- 你的 Link Button 能让用户选择新页面打开吗?
- 【对象——对象及原型链上的属性——对象的操作方法】
- R语言ggplot2可视化:使用ggpubr包的ggerrorplot函数可视化误差线(可视化不同水平均值点以及se标准误差)、设置add参数为dotplot添加点阵图
- Miscellaneous talk - the sorrow of programmers
- typedef和#define的花里胡哨的用法
- leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
- 少儿编程 电子学会图形化编程等级考试Scratch三级真题解析(判断题)2022年6月
- shell array
- 【GORM】模型关系-HasMany关系
- “我“是一名测试/开发程序员,小孙的内心独白......
猜你喜欢
阿里云架构师金云龙:基于云XR平台的视觉计算应用部署
【LaTex】 Font “FandolSong-Regular“ does not contain requested(fontspec)Script “CJK“.如何抑制此种警告?
Postgresql源码(68)virtualxid锁的原理和应用场景
Tencent continues to wield the "big knife" to reduce costs and increase efficiency, and free catering benefits for outsourced employees have been cut
leetcode:286.墙和门
少儿编程 电子学会图形化编程等级考试Scratch三级真题解析(判断题)2022年6月
Swift 需求 如何防止把view重复添加到win里面
17-GuliMall 搭建虚拟域名访问环境
全球不用交税的国家,为什么不交
数字与中文大写数字互转(5千万亿亿亿亿以上的数字也支持转换)
随机推荐
leetcode:331. 验证二叉树的前序序列化
R语言ggplot2可视化:使用ggpubr包的ggerrorplot函数可视化误差线(可视化不同水平均值点以及se标准误差)、设置add参数为dotplot添加点阵图
chart.js面积图曲线图统计插件
OSS文件上传
每日一R「02」所有权与 Move 语义
浅析量股票化交易的发展现状
leetcode brush questions diary Calculate the number of elements on the right that is less than the current element
How to insist to use procedural system?
使用股票量化交易接口需要具备怎么样的心态
Leetcode 236. 二叉树的最近公共祖先
R语言ggplot2可视化:使用ggpubr包的ggscatter函数可视化散点图、使用scale_x_continuous函数的breaks参数指定X轴的断点的个数(设置参数n)
【技术分享】SLA(服务等级协议)原理与配置
请讲一讲JS中的 for...in 与 for...of (上)
杂谈——程序员的悲哀
17-GuliMall 搭建虚拟域名访问环境
B. Neighbor Grid
DXF笔记:文字对齐的研究
CV复习:softmax代码实现
Kubernetes Service对象
重装系统后新建文本文档打不开怎么办