Problem B: STL——集合运算
Description
Input
Output
Sample Input
Sample Output
HINT
Append Code
代码
#include <iostream>
#include <iterator>
#include <set>
#include <algorithm>
using namespace std;
void print(const set<int> &A)
{
set<int>::iterator it;
cout<<"{";
for(it=A.begin();it!=A.end();it++)
{
if(it == A.begin())
cout<<*it;
else cout<<","<<*it;
}
cout<<"}"<<endl;
}
int main()
{
set<int> A;
set<int> B;
set<int> tm1,tm2,tm3,tm4,tm5;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Case# "<<i+1<<":"<<endl;
int a,b;
cin>>a;
for(int j=0;j<a;j++)
{
int t;
cin>>t;
A.insert(t);
}
cin>>b;
for(int j=0;j<b;j++)
{
int t;
cin>>t;
B.insert(t);
}
cout<<"A = ";
print(A);
cout<<"B = ";
print(B);
set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(tm1, tm1.begin()));
cout<<"A u B = ";
print(tm1);
set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(tm2, tm2.begin()));
cout<<"A n B = ";
print(tm2);
set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(tm3, tm3.begin()));
cout<<"A - B = ";
print(tm3);
set_difference(tm1.begin(), tm1.end(), A.begin(), A.end(), inserter(tm4, tm4.begin()));
cout<<"SA = ";
print(tm4);
set_difference(tm1.begin(), tm1.end(), B.begin(), B.end(), inserter(tm5, tm5.begin()));
cout<<"SB = ";
print(tm5);
}
return 0;
}
Problem B: STL——集合运算的更多相关文章
- STL中的set集合容器进行集合运算:并、交、差实例
集合容器的集合运算:并.交.差: #include "stdafx.h" #include <iostream> #include <set> #inclu ...
- [Swust OJ 632]--集合运算(set容器)
题目链接:http://acm.swust.edu.cn/problem/632/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- Problem I: STL——多重集的插入和删除
Problem I: STL--多重集的插入和删除 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1729 Solved: 1258[Submit][ ...
- 【Java EE 学习 28 上】【oracle学习第二天】【子查询】【集合运算】【几种数据库对象】
一.子查询 1.为什么要使用子查询:问题不能一步求解或者一个查询不能通过一步查询得到. 2.分类:单行子查询和多行子查询. 3.子查询的本质:一个查询中包含了另外一个或者多个查询. 4.使用子查询的规 ...
- 详解SQL集合运算
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列[T-SQL基础]主要是针对T-SQL基础的总结. [T-SQL基础]01.单表查询-几道sql查询题 ...
- SQL集合运算参考及案例(一):列值分组累计求和
概述 目前企业应用系统使用的大多数据库都是关系型数据库,关系数据库依赖的理论就是针对集合运算的关系代数.关系代数是一种抽象的查询语言,是关系数据操纵语言的一种传统表达方式.不过我们在工作中发现,很多人 ...
- Oracle学习之集合运算
一.集合运算操作符 UNION:(并集)返回两个集合去掉重复值的所有的记录 UNION ALL:(并集)返回两个集合去掉重复值的所有的记录 INTERSECT:(交集)返回两个集合的所有记录,重复 ...
- Oracle学习(七):集合运算
1.知识点:能够对比以下的录屏进行阅读 SQL> -- 查询10和20号部门的员工的3种方法 SQL> --1. select * from emp where deptno in (10 ...
- sql的集合运算
表的加减法 union:使用union 对表进行假发(并集)运算, union等集合运算符通常都会去除重复记录. select shohin_id, shohin_mei from shohin un ...
随机推荐
- aop(execution()表达式)
execution(* com.tp.soft.service..*.*(..)) 整个表达式可以分为五个部分: 1.execution(): 表达式主体. 2.第一个*号:表示返回类型,*号表示所有 ...
- Oracle创建表、修改字段类型
1.创建表 1.创建表 create table SCM_PER( --SCM_PER表名 ID ) primary key,--主键ID USERID ),--用户ID --Permission v ...
- vue history模式
注意: 1.前端:config.js路径问题 2.后台:配置nginx
- Disable access to Windows Update
Disable access to Windows Update If this policy setting is enabled, all Windows Update features are ...
- C++实现的一些功能代码
将当前时间输出到txt中: 调用c++中的fstream流文件,用tm结构获取日期和时间,其在time.h中定义 用ofstream的时候,ofstream out(txtpath,ios::app) ...
- 【官方下载】EasyCMDB官方基础版免费下载使用!
链接
- 20190412wdVBA 排版
Sub LayoutForExamPaper() Dim StartTime As Variant Dim UsedTime As Variant StartTime = VBA.Timer Appl ...
- Vue 组件的使用
1.引入组件 import Week from '../week/main.vue' export default { name: "classMain", components: ...
- EF中关于日期字值的处理
一.SQL语句方式 var datefrom = DateTime.Parse(fromdate); var dateto = DateTime.Parse(todate); var sql = ...
- 华为S5700设置vlan,并绑定电脑的IP地址与mac地址。
要求是设置两个vlan,10和20.交换机下的10网段和20网段的电脑在两个vlan当中.20网段的ip地址与mac地址绑定,从而实现下面的电脑更改ip地址或者不明来源的电脑不能连接到交换机. 1.s ...