-
Notifications
You must be signed in to change notification settings - Fork 0
/
1007.c
46 lines (41 loc) · 960 Bytes
/
1007.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
#include<string.h>
char str[101][51];
int cnt[26];
int sortedness[101], tmp[101];
int main(){
int n, m, c, i, k;
int cur, len;
char j;
freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &m);
c = 0;
while(c < m){
memset(cnt, 0, sizeof(cnt));
scanf("%s", str[c]);
sortedness[c] = 0;
for(i = n - 1; i >= 0; i--){
sortedness[c] += cnt[str[c][i] - 'A'];
for(j = str[c][i] + 1; j <= 'Z'; j++){
cnt[j - 'A']++;
}
}
c++;
}
cur = len = 0;
for(i = 0; i < m; i++){
cur = len - 1;
while(cur >= 0 && sortedness[i] < sortedness[tmp[cur]])
cur--;
cur++;
for(k = len; k >= cur; k--){
tmp[k] = tmp[k - 1];
}
tmp[cur] = i;
len++;
}
for(i = 0; i < m; i++){
printf("%s\n", str[tmp[i]]);
}
return 0;
}