import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static Scanner cin;
// 求逆序数
public static int niXuShu(int n, String str) {
int a, b;
char[] c = new char[n];
c = str.toCharArray();
b = 0;
for (int i = 0; i < c.length - 1; i++) {
a = 0;
for (int k = i + 1; k < c.length; k++) {
if (c[i] > c[k])
a++;
}
b += a;
}
return b;
}
// 排序
public static void sort(int[] numbers) {
int temp = 0;
int size = numbers.length;
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - 1 - i; j++) {
if (numbers[j] > numbers[j + 1]) {
temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
}
public static void main(String[] args) {
cin = new Scanner(System.in);
int n = 0; // 字符串长度
int m = 0; // 字符串数量
String str;
int[] s; // 储存逆序数
Map<Integer, String> ma = new HashMap<Integer, String>();
n = cin.nextInt();
m = cin.nextInt();
s = new int[m];
for (int i = 0; i < m; i++) {
str = cin.next();
s[i] = niXuShu(n, str);
ma.put(s[i], str);
}
sort(s);
for (int i = 0; i < m; i++)
System.out.println(ma.get(s[i]));
}
}
poj1007 DNA Sorting
最新推荐文章于 2018-05-02 17:53:23 发布