#include<stdio.h> #include<string.h> struct ch{ char s[100]; int num; }c[100],temp; int main() { int n,m,i,j,k,count=0; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<m;i++) {scanf("%s",c[i].s); {for(k=0;k<n;k++) for(j=k+1;j<n;j++) if(c[i].s[k]>c[i].s[j]) count++; } c[i].num=count; count=0; } for(i=0;i<m-1;i++) for(j=0;j<m-1-i;j++) if(c[j].num>c[j+1].num) { temp=c[j]; c[j]=c[j+1]; c[j+1]=temp; } for(i=0;i<m;i++) printf("%s\n",c[i].s); } } |
Double click to view unformatted code.