人见人爱A-B HDU
来源:互联网 发布:如何让linux自启动脚本 编辑:程序博客网 时间:2024/06/07 15:54
人见人爱A-B HDU - 2034
Problem
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)
呵呵,很简单吧?
Input
每组输入数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),分别表示集合A和集合B的元素个数,然后紧跟着n+m个元素,前面n个元素属于集合A,其余的属于集合B. 每个元素为不超出int范围的整数,元素之间有一个空格隔开.
如果n=0并且m=0表示输入的结束,不做处理。
Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
Sample Input
3 3 1 2 3 1 4 7
3 7 2 5 8 2 3 4 5 6 7 8
0 0
Sample Output
2 3
NULL
ps:明确{A}-{B}的算法,要求从小打到大输出
代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string.h> using namespace std; int main() { int n, m; while(~scanf("%d %d", &n, &m) && (n+m)) { int a[105], b[105]; int i, j, flag = 0, k; for(i = 0; i < n; i++) scanf("%d", &a[i]); for(i = 0; i < m; i++) scanf("%d", &b[i]); sort(a, a + n); //必须排序 for(i = 0; i < n; i++) { for(j = 0, k = 0; j < m; j++) { if(a[i] != b[j]) k++; else break; } if(k == m) { printf("%d ", a[i]); flag = 1; } } if(flag == 0) printf("NULL\n"); else printf("\n"); } return 0; }
阅读全文
0 0
- hdu-人见人爱A^B
- hdu-人见人爱A+B
- hdu 人见人爱A^B
- HDU 人见人爱A^B
- 人见人爱A-B HDU
- 人见人爱A^B HDU
- 人见人爱A^B HDU
- (hdu 2035)人见人爱A^B
- HDU 2035 ( 人见人爱A^B )
- hdu 2033 人见人爱A+B
- HDU 2033 人见人爱A+B
- HDU 2035 人见人爱A^B
- hdu 2034 人见人爱A-B
- hdu 2035人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- HDU 2035 人见人爱A^B
- hdu 2034 人见人爱A-B
- 操作系统课设之在线文档管理(2)
- Redis配置认证密码
- 理解mnist识别特征(lenet)
- API 文档
- 硕士的进与退,我为什么选择FPGA?
- 人见人爱A-B HDU
- AP和BP概念——手机
- Java基础-hashMap的相关问题
- 硬链接与软链接
- STL源码学习----lower_bound和upper_bound算法
- js实现工作日期选中的日历
- 浅谈python中的“ ==” 与“ is”
- EOS
- 非接触CPU卡外部认证步骤