题解 | #有序序列合并#
有序序列合并
https://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
#include <stdio.h> int main() { int n = 0; int m = 0; scanf("%d %d", &n, &m);//输入每个数组元素个数 int arr1[n];//定义 int arr2[m];//c99 int a = m + n; int i = 0; for (i = 0; i < n; i++)//输入 { scanf("%d ", &arr1[i]); } for (i = 0; i < m; i++) { scanf("%d ", &arr2[i]); } int arr3[a]; for (i = 0; i < m + n; i++)//合并格式 { if (i < n) { arr3[i] = arr1[i]; } else { arr3[i] = arr2[i - n]; } } for (i = 0; i < m + n - 1; i++)//冒泡排序 { int j = 0; for (j = 0; j < m + n - 1 - i; j++) { if (arr3[j] > arr3[j+1]) { int temp = arr3[j]; arr3[j] = arr3[j+1]; arr3[j+1] = temp; } } } for (i = 0; i < m + n; i++)//打印输出 { printf("%d ", arr3[i]); } return 0; }
C语言基础 文章被收录于专栏
里面较为详细的介绍了c语言的相关用法和有关题目。