游客 Signup | Login
中文 | En

1839 - 课后习题7.4

已有一个已排好的9个元素的数组,今输入一个数要求按原来排序的规律将它插入数组中。

Input

第一行,原始数列。 第二行,需要插入的数字。

Output

排序后的数列

Examples

Input

1 7 8 17 23 24 59 62 101
50

Output

1
7
8
17
23
24
50
59
62
101

Solution C

#include<stdio.h>
void insertsort(int a[],int m);
int main()
{
	int i,a[10];
	for(i=0;i<9;i++)
		scanf("%d",&a[i]);
	scanf("%d",&a[9]);
	insertsort(a,10);
	for(i=0;i<10;i++)
		printf("%d\n",a[i]);
	return 0;
}
void insertsort(int a[],int m)
{
	int i,j;
	int temp;
	for(i=1;i<m;i++)
	{
		temp=a[i];
		for(j=i;j>0&&a[j-1]>temp;j--)
			a[j]=a[j-1];
		a[j]=temp;
	}
}

Solution C++

#include<bits/stdc++.h>
using namespace std;
long long a[1000000];
int main()
{
	for(int i=1;i<=10;i++)
		cin>>a[i];
	sort(a+1,a+11);
	for(int i=1;i<=10;i++)
		cout<<a[i]<<"\n";
		
    return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题