Posted on 2008-04-13 09:11
superman 阅读(282)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1188 C++ 00:00.03 1340K */
2 #include <string>
3 #include <iostream>
4
5 using namespace std;
6
7 int main()
8 {
9 int N;
10 cin >> N;
11
12 while(N--)
13 {
14 int n, m;
15 cin >> m >> n;
16
17 string s[100];
18 for(int i = 0; i < n; i++)
19 cin >> s[i];
20
21 int max = 0;
22 int cnt[1250][101] = {0};
23 for(int k = 0; k < n; k++)
24 {
25 int sum = 0;
26 for(int i = 0; i < m; i++)
27 for(int j = i + 1; j < m; j++)
28 if(s[k][i] > s[k][j])
29 sum++;
30 max >?= sum;
31 cnt[sum][0]++;
32 cnt[sum][cnt[sum][0]] = k;
33 }
34
35 for(int i = 0; i <= max; i++)
36 if(cnt[i][0])
37 for(int j = 1; j <= cnt[i][0]; j++)
38 cout << s[cnt[i][j]] << endl;
39
40 if(N)
41 cout << endl;
42 }
43
44 return 0;
45 }
46