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