题解 | #逆序输出#
有序序列合并
http://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
int main()
{
int n = 0, m = 0;
scanf("%d %d", &n, &m);
int arr[5000] = {0};
//之前定义的数组元素个数为1000,测试用例通过但是提交不通过,找了好久也没发现哪里写错了,后来
//改成5000便通过了,我吐了哈...
int i = 0, j = 0, num = 0;
for(i = 0; i < n; i ++)
{
scanf("%d", &num);
arr[i] = num;
}
for(j = 0; j < m; j ++)
{
scanf("%d",&num);
arr[i+j] = num;
}
//冒泡排序
for(i = 0; i < n+m; i ++)
{
for(j = 0; j < n+m-i-1; j ++)
{
if(arr[j] > arr[j+1])
{
int tmp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = tmp;
}
}
}
for(i = 0; i < n+m; i ++)
{
printf("%d ",arr[i]);
}
return 0;
}