https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=553
困難度 ★ 這題依題意算出每個字串的數字再將之排序把原來的字串從小到大印出來
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=Integer.parseInt(scn.nextLine());
Boolean boo=false;
while(n--!=0){
if(boo)
System.out.println();
int a=scn.nextInt(),b=scn.nextInt(),max=0,ans[]=new int [b],count=0;
String s[]=new String[b];
for(int i=0;i<b;i++)
s[i]=scn.next();
for(int i=0;i<b;i++){
char arr[]=s[i].toCharArray();
for(int j=0;j<a-1;j++){
for(int k=j+1;k<a;k++){
if(arr[j]>arr[k])
count++;
}
}
ans[i]=count;
if(count>max)
max=count;
count=0;
}
for(int i=0;i<=max;i++){
for(int j=0;j<b;j++){
if(ans[j]==i)
System.out.println(s[j]);
}
}
boo=true;
}
/*
題目:Q612 : DNA Sorting
作者:1010
時間:西元 2016 年 8 月 */
}
}