题解 | #有序序列插入一个整数#
有序序列插入一个整数
http://www.nowcoder.com/practice/444e87f938464906a1649cff236b102b
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c, t[55], n = 0;
cin >> a;
for (int i = 0; i < a; i++)
{
cin >> b;
t[i] = b;
}
cin >> c;
for (int i = 0; i < a; i++)
{
if (c < t[i])
break;
n++;
}
for (int i = a - 1; i >= n ; i--)
{
t[i + 1] = t[i];
}
t[n] = c;
for (int i = 0; i <= a; i++)
cout << t[i] << " ";
return 0;
}