题解 |两数组重排列
有序序列合并
http://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
#include<stdio.h>
int main()
{
int a=0, b;
scanf("%d%d", &a, &b);
//scanf("%a%b", &a, &b);
int arr[20] = { 0 };
int arr2[20] = { 0 };
for (int i = 0; i < a; i++)
{
scanf("%d", &arr[i]);
}
for (int i = 0; i < b; i++)
{
scanf("%d", &arr2[i]);
}
int arr3[40] = { 0 };int m = 0;
for (int i = 0; i < a + b; i++)
{
if (i < a)
{
arr3[i] = arr[i];
m = i+1;
}
else
arr3[i] = arr2[i - m];
}
//冒泡排序
for (int i = 0; i < a + b - 1; i++)
{
for (int m = 0; m < a + b - 1-i; m++)
{
if (arr3[m] > arr3[m+1])
{
int t = 0;
t = arr3[m + 1];
arr3[m + 1] = arr3[m];
arr3[m] = t;
}
}
}
for (int i = 0; i < a + b; i++)
{
printf("%d ", arr3[i]);
}
return 0;
}
int main()
{
int a=0, b;
scanf("%d%d", &a, &b);
//scanf("%a%b", &a, &b);
int arr[20] = { 0 };
int arr2[20] = { 0 };
for (int i = 0; i < a; i++)
{
scanf("%d", &arr[i]);
}
for (int i = 0; i < b; i++)
{
scanf("%d", &arr2[i]);
}
int arr3[40] = { 0 };int m = 0;
for (int i = 0; i < a + b; i++)
{
if (i < a)
{
arr3[i] = arr[i];
m = i+1;
}
else
arr3[i] = arr2[i - m];
}
//冒泡排序
for (int i = 0; i < a + b - 1; i++)
{
for (int m = 0; m < a + b - 1-i; m++)
{
if (arr3[m] > arr3[m+1])
{
int t = 0;
t = arr3[m + 1];
arr3[m + 1] = arr3[m];
arr3[m] = t;
}
}
}
for (int i = 0; i < a + b; i++)
{
printf("%d ", arr3[i]);
}
return 0;
}