#include "stdio.h" #include "math.h" #include "string.h" void main() { char a[200][200]; char b[200][200]; char temp[200]; int m,n,i,j,k; char c; int t; int count[200]={0}; scanf("%d%d",&n,&m); for(i=0;i<m;i++) { scanf("%s",a[i]); strcpy(b[i],a[i]); } for(k=0;k<m;k++) { for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(a[k][j]>a[k][j+1]) { c=a[k][j];a[k][j]=a[k][j+1];a[k][j+1]=c; //必须换,下次还得比较呢 count[k]++; } } } } for(k=0;k<m;k++) { for(i=0;i<m-k-1;i++) { if(count[i]>count[i+1]) { strcpy(temp,b[i]);strcpy(b[i],b[i+1]);strcpy(b[i+1],temp); t=count[i];count[i]=count[i+1];count[i+1]=t; } } } for(k=0;k<m;k++) { printf("%s\n",b[k]); } } |
Double click to view unformatted code.