Problem : 1412 ( {A} + {B} )

时间:2023-03-08 21:15:09
Problem : 1412 ( {A} + {B} )
//集合中元素是不会重复的,所以完全没有必要将两个集合合并后再进行排序,交换排序的时间效率是O(n^2),将两个集合中的元素分别排序后输出即可。输出格式也非常需要
//注意的。输出一列元素赢以cout<<a[0];然后在循环中输出printf(" %d",a[i]);这样的细节是非常需要加以留心的。
#include<iostream>
using namespace std;
int *swap(int *p,int t);
void main()
{ int n,m; while(cin>>n>>m)
{
int a[20000],b[10000];
int *p;
int temp;
int t=m+n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
for(int i=n;i<t;i++)
{
a[i]=b[i-n];
}
p=swap(a,t);
temp=p[0];
cout<<p[0];
for(int i=1;i<t;i++)
{
if(p[i]!=temp)
printf(" %d",p[i]);
temp=p[i];
}
cout<<endl;
} }
int *swap(int *p,int t)
{
int temp;
for(int i=0;i<t;i++)
{
for(int j=i+1;j<t;j++)
{
if(p[j]<p[i])
{
temp=p[j];
p[j]=p[i];
p[i]=temp;
}
}
}
return p;
}