1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 int len, num;
7 int i, j, k, temp, count[100], order[100];
8 char s[100][51];
9
10 cin >> len >> num;
11
12 for (i = 0; i < num; ++i)
13 {
14 order[i] = i;
15 cin >> s[i];
16 for (j = 0; j < len - 1; ++j)
17 for (k = j + 1; k < len; ++k)
18 if (s[i][j] > s[i][k])
19 ++count[i];
20 }
21
22 for (i = 0; i < num; ++i)
23 for (j = 0; j < num - i - 1; ++j)
24 if (count[j] > count[j + 1])
25 {
26 temp = order[j];
27 order[j] = order[j + 1];
28 order[j + 1] = temp;
29 temp = count[j];
30 count[j] = count[j + 1];
31 count[j + 1] = temp;
32 }
33
34 for (i = 0; i < num; ++i)
35 cout << s[order[i]] << endl;
36
37 return 0;
38 }