将一正整数序列{K1,K2,...,K9}重新排列成一个新的序列。新序列中,比K1小的数都在K1的前面(左面),比K1大的数都在K1的后面(右面)。
输入有多行,第一行为N表示行数,每行9个整数.
输出N行,按要求进行排序的结果.
2 6 8 9 1 2 5 4 7 3 3 5 8 9 1 2 6 4 7
3 4 5 2 1 6 8 9 7 2 1 3 5 8 9 6 4 7
import java.util.Scanner;
public class Main {
public static void main(String[]ages){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
while(n-->0)
{
int a=sc.nextInt();
int front[] =new int [9];//前面的数组储存比第一个数小的
int behind[]=new int [9];//后面的数组储存比第一个数大的
int b=0;//dex指标
int c=0;//dex指标
int l=0;//dex指标
int p=0;//dex指标
for(int i=0;i<8;i++)
{
int g=sc.nextInt();
if(g>a){
behind[b++]=g;
p++;//指标++
}
else
{
front[c++]=g;
l++;//指标++
}
}
for(int i=l-1;i>=0;i--)//............front[]逆序输出
System.out.print(front[i]+" ");
System.out.print(a+" ");
for(int i=0;i<p;i++)//..........behind顺序输出
System.out.print(behind[i]+" ");
System.out.println();
}
}
}