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