题解 | #有序序列合并#
有序序列合并
https://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
int main() { int i = 0, n = 0,m=0,j=0; scanf("%d%d", &n, &m); int arr[1000] = { 0 }; int drr[1000] = { 0 }; int crr[3000] = { 0 }; //输入 for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i = 0; i < m; i++) { scanf("%d", &drr[i]); } int p = m + n; //判断三种情况,谁的数组小,就放前面 if(m>n||m==n||m<n) { for (i = 0; i < p; i++) { if (i < m) { crr[i] = drr[i]; } else { crr[i] = arr[j++]; } } } //冒泡排序 for (i = 0; i < p; i++) { for (int j = 0; j < p - i - 1; j++) { if (crr[j] > crr[j + 1]) { int temp = crr[j+1]; crr[j+1] = crr[j]; crr[j] = temp; } } } for (i = 0; i < p; i++) { printf("%d ", crr[i]); } return 0; }