{A} + {B}
Time Limit:5000MS Memory Limit:65536K
Total Submit:15 Accepted:1
Description
Given Two collections {A} and {B}.
Note: there are no two same elements in each collections.
Input
The problem has many test cases.
For each case,there are three lines.
The first line contains two integer n and m (0 < n,m <= 10000). n is the number of {A}'s elements, and m is the number of {B}'s elements.
The second line is the elements of {A}.
The third line is the elements of {B}.
Output
For each case, output one line containing all the elements in the combination of collections {A} and {B}. You should order the elements by ascend(from small one to big one).
Sample Input
1 2
1
2 3
1 2
1
1 2
Sample Output
1 2 3
1 2
我的代码
//07-8-7 zist 2507 {A} + {B}
#include <stdio.h>
void SortBullbe(int *a ,int n)
{
int i ,j ,k ,temp;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(a[k]>a[j])
{
k=j;
}
}
if(k!=i)
{
temp=a[i];
a[i]=a[k];
a[k]=temp;
}
}
}
main()
{
int i ,j ,k ,n ,m ,l ,count=0 ,flag=0;
int a[10005] ,b[10005] ,c[20005];
while(scanf("%d%d",&n,&m)!=EOF)
{
count=0 ;
flag=0;
for(i=0;i < n;i++)
{
scanf("%d",&a[i]);
}
SortBullbe(a ,n) ;
for(i=0;i < m;i++)
{
scanf("%d",&b[i]);
}
SortBullbe(b ,m) ;
if(a[n-1]<b[0])
{
for(i=0 ;i <n;i++)
{
printf("%d ",a[i]);
}
for(i=0 ;i <m;i++)
{
printf("%d ",b[i]);
}
}
else
{
k=0; l=0 ;
for(i=0 ;i < n;i++)
{
for(j=i+k;j < m;j++)
{
if(a[i] < b[j])
{
c[count++]=a[i];
break;
}
if(a[i]>b[j])
{
c[count++]=b[j];
l++ ;
continue;
}
if(a[i]==b[j])
{
c[count++]=a[i];
break;
}
}
if(l>0)
k=l;
if(j==m)
{
flag=1;
break;
}
}
if(flag==0)
{
for( ;j < m-1 ;j++)
{
c[count++]=b[j+1];
}
}
if(flag==1)
{
for( ;i < n;i++)
{
c[count++]=a[i];
}
}
for(i=0 ;i <count;i++)
{
printf("%d ",c[i]);
}
}
printf("\n");
}
}
大家帮忙看下错误,我在 本地调试的时候通过了的,可提交上去就是说我的answer error,我实在看不出错误了,大家帮忙看下,
[此贴子已经被作者于2007-8-7 14:05:32编辑过]