HDU 2034 人见人爱A-B(水~)
来源:互联网 发布:韩国网络爆红65g 编辑:程序博客网 时间:2024/05/21 11:23
Description
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{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
Solution
水题,把集合A中在集合B中出现过的元素标记下即可
Code
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){ int n,m; while(scanf("%d%d",&n,&m),n||m) { int a[111],b[111],vis[111]={0}; for(int i=0;i<n;i++) cin>>a[i]; int temp=n; for(int i=0;i<m;i++) { cin>>b[i]; for(int j=0;j<n;j++) if(a[j]==b[i]&&!vis[j]) vis[j]=1,temp--; } sort(a,a+n); if(temp) { for(int i=0,j=0;i<n;i++) if(!vis[i]) printf("%d ",a[i]); } else printf("NULL"); printf("\n"); } return 0;}
0 0
- HDU 2034 人见人爱A-B(水~)
- 【HDU 2034】人见人爱A-B 水
- hdu 2034 人见人爱A-B (java)
- HDU 2033 人见人爱A+B(水~)
- HDU 2035 人见人爱A^B(水~)
- hdu 2034 人见人爱A-B
- hdu 2034 人见人爱A-B
- HDU 2034 人见人爱A-B
- hdu 2034 人见人爱A-B
- hdu 2034 人见人爱A-B
- hdu-2034-人见人爱A-B
- HDU 2034 - 人见人爱A-B
- hdu 2034 人见人爱A-B
- [hdu 2034] 人见人爱A-B
- HDU 2034 人见人爱A-B
- HDU 2034 人见人爱A-B
- hdu-2034-人见人爱A-B
- hdu 2034 人见人爱A-B
- ServletContext
- HDU 2033 人见人爱A+B(水~)
- 专注是通向成功的直通车
- multiprocessing在python中的高级应用-IPC 之 Pipe
- C、置换的玩笑-------(计蒜之道 测试赛)
- HDU 2034 人见人爱A-B(水~)
- 学习《算法导论》第六章 堆排序 总结二
- Android Binder 机制
- Html5 Blob
- leetcode 234 Palindrome Linked List(难易度:Easy)
- HDU 2035 人见人爱A^B(水~)
- HDOJ 2682 Tree
- C++各数据类型取值范围
- 讯飞离线语音合成(语记|语音+)