1112:数列排序
Descrioption
将一正整数序列{K1,K2,...,K9}重新排列成一个新的序列。新序列中,比K1小的数都在K1的前面(左面),比K1大的数都在K1的后面(右面)。
Input
输入有多行,第一行为N表示行数,每行9个整数。
Output
输出N行,按要求进行排序的结果。
Sample Input
2
6 8 9 1 2 5 4 7 3
3 5 8 9 1 2 6 4 7
Sample Output
3 4 5 2 1 6 8 9 7
2 1 3 5 8 9 6 4 7
#include<stdio.h>
int main()
{
int N,i;
scanf("%d",&N);
int a[100],b[100],c[100];
while(N--)
{
for(i=0; i<9; i++)
scanf("%d",&a[i]);
int temp;
int t=0,s=1;
for(i=0; i<9; i++)
{
if(a[0]>a[i])
{
b[t]=a[i];
t++;
}
else
{
c[s]=a[i];
s++;
}
}
for(i=t-1; i>=0; i--)
printf("%d ",b[i]);
for(i=1; i<s; i++)
if(i==s-1)
printf("%d",c[i]);
else
printf("%d ",c[i]);
printf("\n");
}
return 0;
}