离散题目5

来源:互联网 发布:宝贝关键词怎么优化 编辑:程序博客网 时间:2024/06/03 11:55

离散题目5

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

DaYu收藏了许多电影,他有个志同道合的小伙伴DiGou也收藏了许多电影(电影编号<10000),这天,DaYu把DiGou的电影拷贝到自己的电脑上,他想知道现在他的电脑上有哪些电影。请你帮他列出他电脑上所有电影的编号。因为DaYu和DiGou心有灵犀,所以他们的小电影命名方式相同,同样的电影的编号相同。按照编号从小到大输出。

Input

多组输入,每组的第一行输入两个数m(0 < m < 10000)和n( 0 < n < 10000 ),之后的两行分别有m和n个数字,代表DaYu和DiGou的电影编号。

Output

对于每组数据,输出一行从小到大排序的电影编号,最后一个数字后面没有空格.

Example Input

5 51 2 3 4 51 5 3 6 7

Example Output

1 2 3 4 5 6 7
think:直接将所有的数据存到一个数组里面,然后不重复的输出即可。
代码:#include <bits/stdc++.h>using namespace std;int main(){int n, m;int a[20005];while(cin>>m>>n){for(int i = 0; i < m+n; i++)cin>>a[i];sort(a, a+m+n);int count = 0;for(int i = 0; i < m+n; i++){if(a[i] != a[i-1]){if(count == 0)                   cout<<a[i];                else                   cout<<" "<<a[i];                   count++; }}cout<<endl;}return 0;}
原创粉丝点击