题解 | #有序序列合并#
有序序列合并
https://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
#include <stdio.h> #include <stdlib.h> int main() { int n, m; scanf("%d %d", &n, &m); //分配空间 int* arr = (int*)malloc(sizeof(int) * (n+m)); //存储 size_t i = 0; while(i < m+n) { scanf("%d", &arr[i]); ++i; } //排序 for(i=0; i<m+n-1; ++i) { size_t j = 0; for(j=0; j<m+n-1-i; ++j) { if(arr[j] > arr[j+1]) { int tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } //输出 for(i=0; i<m+n; i++) { printf("%d ", arr[i]); } printf("\n"); //释放空间 free(arr); arr = NULL; return 0; }