题目链接: http://codeup.cn/problem.php?cid=100000569&pid=0
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[10], toSort, i;
int j=8;//开始查找的位置
for(i=0;i<9;i++) {
scanf("%d",&a[i]);
}
scanf("%d",&toSort);
while(j>=0 && a[j]>toSort) {//直接插入排序
a[j+1] = a[j];
j-=1;
}
a[j+1]=toSort;
for(i=0;i<10;i++) {
printf("%d\n",a[i]);
}
return 0;
}
运行结果