import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//思路:将输入的字符串存入数组中,再对其计算,最后进行排序
int length = scan.nextInt();
int times = scan.nextInt();
String[] arr = new String[times];
int[] arr1 = new int[times];
Integer count = 0;
for(int i=0;i<times;i++){
arr[i] = scan.next();
if(arr[i].length()!=length){
return;
}
count = count(arr[i]);
arr1[i] = count;
}//for
//排序
for(int x=0;x<arr1.length;x++){
for(int y=x;y<arr1.length;y++){
if(arr1[x]>arr1[y]){
int temp1 = arr1[y];
arr1[y] = arr1[x];
arr1[x] = temp1;
String temp = null;
temp = arr[y];
arr[y] = arr[x];
arr[x] = temp;
}
}
System.out.println(arr[x]);
}
}
private static int count(String str) {
int sum = 0;
char[] arr = str.toCharArray();
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
if(arr[i]>arr[j]){
sum++;
}
}
}//for
return sum;
}
}
Poj1007
最新推荐文章于 2015-12-08 22:10:29 发布