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 ...
随机推荐
- Unity外包 UE4外包 项目案例平台开通通知
长年承接Unity外包 UE4外包,大家好,本公司团队已将案例上传至专门的案例官网. 欢迎联系我们索取,谢谢! 有项目外包请联系QQ:372900288 索取案例.
- java在window下用cmd (javac、jar)命令行模拟Intellij IDEA软件生成jar包
@@首先最重要的cmd命令: javac ,jar :使用如下(注意[.]不要输错): 1. javac编译: D:\MyWorkSet\idea_hadoop>javac -d .\out\p ...
- libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
In Xcode 9 and Swift 4: Print exception stack to know the reason of the exception: Go to show break ...
- H5外包团队:使用HTML5播放短视频代码分享
滑动代码 /** * 滑动处理 */ function Touch() { this.init(); } Touch.fn = Touch.prototype; Touch.fn.init = fun ...
- Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app
出现的问题: Error:Execution failed for task ':app:preDebugAndroidTestBuild'.> Conflict with dependency ...
- (转)如何在maven的pom.xml中添加本地jar包
转载自: https://www.cnblogs.com/lixuwu/p/5855031.html 1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下 ...
- android ----- 分享的连接在手机上打开App
首先做成HTML的页面,页面内容格式如下: <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 这一 ...
- android -------- 沉浸式状态栏和沉浸式导航栏(ImmersionBar)
android 4.4以上沉浸式状态栏和沉浸式导航栏管理,包括状态栏字体颜色,适用于Activity.Fragment.DialogFragment.Dialog,并且适配刘海屏,适配软键盘弹出等问题 ...
- promise用法十道题
JS是单线程语言,多数的网站不需要大量计算,程序耗时主要是在磁盘I/O和网络I/O上 ,虽然固态硬盘SSD读取很快,但是和CPU比起来却不在一个数量级上,而且网络上的一个数据包来回时间更慢,所以一些C ...
- 43. Multiply Strings字符串相乘
网址:https://leetcode.com/problems/multiply-strings/submissions/ 参考:https://leetcode.com/problems/mult ...