E - {A}+{B}(10)
Problem Description
给你两个集合,要求{A} + {B}.
注:同一个集合中不会有两个相同的元素.Input
每组输入数据分为三行,第一行有两个数字n,m(0<n,m<=10000),分别表示集合A和集合B的元素个数.后两行分别表示集合A和集合B.每个元素为不超出int范围的整数,每个元素之间有一个空格隔开.
Output
针对每组数据输出一行数据,表示合并后的集合,要求从小到大输出,每个元素之间有一个空格隔开.
Sample Input
1 2 1 2 3 1 2 1 1 2
Sample Output
1 2 3 1 2
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, j, n, m, t;
int a[20001];
while(~scanf("%d %d", &n, &m))
{
for(i = 0; i < n+m; i++)
{
scanf("%d", &a[i]);
}
for(i = 0; i < m+n-1; i++) //冒泡
{
for(j = 0; j<m+n-1-i; j++)
{
if(a[j+1] < a[j])
{
t = a[j+1];a[j+1] = a[j];a[j] = t;
}
}
}
printf("%d",a[0]);
for(i = 1; i < m+n; i++)
{
if(a[i] != a[i-1]) printf(" %d", a[i]);
}
printf("\n");
}
return 0;
}
Status | Accepted |
---|---|
Time | 858ms |
Memory | 1284kB |
Length | 639 |
Lang | GCC |
Submitted | 2018-08-10 17:08:11 |