0089:倒置排序
总时间限制:
1000ms
内存限制:
32767kB
描述
将一些整数按倒置值排序后输出. 所谓倒置,是指把整数各位倒过来构成一个新数,例如:13倒置成了31.
输入
第一行的整数N表示后面列出的组数。每组数的第一个整数n表示后面将有n个整数。(每组数据量不超80)
输出
将每组数按倒置值进行排序输出.其每组数的结果占一行.
样例输入
2 4 83 13 24 36 4 99 100 123 12345
样例输出
13 83 24 36 100 99 123 12345
来源
重庆科技学院 WJQ
全局题号
11923
添加于
2018-07-09
提交次数
9
尝试人数
4
通过人数
4
你的提交记录
# | 结果 | 时间 |
09-19 |
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
int T=cin.nextInt();
for(int q=1;q<=T;q++)
{
int n=cin.nextInt();
AA [] a=new AA[n+1];
for(int j=0;j<n;j++)
{
a[j]=new AA();
int x=cin.nextInt();
a[j].in(x,x);
}
for(int i=0;i<n;i++)
{
int sum=0;
int g=a[i].x;
int h=0;
while(g!=0)
{
g/=10;
h++;
}
double k=Math.pow(10, h);
while(a[i].x!=0)
{
int t=a[i].x%10;
a[i].x/=10;
sum+=t*k;
k/=10;
}
a[i].x=sum;
}
Arrays.sort(a,0,n, new MyComprator());
for(int i=0;i<n;i++)
{
System.out.print(a[i].y+" ");
}
System.out.println();
}
}
}
class AA
{
public int x,y;
public void in(int x,int y)
{
this.x=x;
this.y=y;
}
}
class MyComprator implements Comparator<AA> {
public int compare(AA t1, AA t2) {
if(t1.x>t2.x)
{
return 1;
}
else
return -1;
}
}