题解 | #有序序列插入一个整数#
有序序列插入一个整数
https://www.nowcoder.com/practice/444e87f938464906a1649cff236b102b
#include <stdio.h> int main() { int n; int arr[50] = {0}; scanf("%d",&n); for (int i = 0; i < n; i++) scanf("%d", &arr[i]); int new; scanf("%d", &new); if(new<=arr[0]) printf("%d ",new); for (int i = 0; i < n - 1; i++) { printf("%d ", arr[i]); if (new >= arr[i] && arr[i + 1] >= new) printf("%d ", new); } printf("%d ", arr[n - 1]); if(new>=arr[n-1]) printf("%d ",new); }