参考:https://www.cnblogs.com/Eric-keke/p/4679590.html
https://blog.csdn.net/leelitian3/article/details/79293058
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 const int N=155;//数组要开大,但是不懂为什么开55时过不了! 7 const int M=105; 8 char s[M][N]; 9 int n,m; 10 struct node 11 { 12 int sn,v; 13 }no[N]; 14 int measure(int x) 15 { 16 int l=strlen(s[x]),va=0; 17 for (int i=0;i<l;i++) 18 { 19 for (int j=i+1;j<l;j++) 20 { 21 if (s[x][j]<s[x][i]) 22 { 23 va++; 24 } 25 } 26 } 27 return va; 28 } 29 bool cmp(struct node x,struct node y) 30 { 31 if (x.v<y.v) 32 { 33 return true; 34 } 35 else 36 { 37 return false; 38 } 39 } 40 void test() 41 { 42 for (int i=0;i<m;i++) 43 { 44 cout<<s[i]<<endl; 45 } 46 } 47 int main() 48 { 49 // freopen("F:\ACM\text.txt","r",stdin); 50 while (cin>>n>>m) 51 { 52 for (int i=0;i<m;i++) 53 { 54 cin>>s[i]; 55 no[i].sn=i; 56 no[i].v=measure(i); 57 } 58 sort(no,no+m,cmp); 59 for (int j=0;j<m;j++) 60 { 61 cout<<s[no[j].sn]<<endl; 62 } 63 } 64 65 return 0