#include<iostream> #include<string.h> using namespace std; int main(){ int n,m; while(cin>>n>>m){ //string a[m]; //for(int i=0;i<m;i++)cin>>a[i]; char s[m][n]; for(int i=0;i<m;i++)cin>>s[i]; int a[m]={0}; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ for(int k=j;k<n;k++){ if(s[i][j]>s[i][k])a[i]++; } } } int temp=0; for(int k=0;k<m;k++){ int temp=0; for(int i=0;i<m;i++){ if(a[i]<a[temp]){ temp=i; } } for(int i=0;i<n;i++){ cout<<s[temp][i]; } cout<<'\n'; a[temp]=999; } } } |
Double click to view unformatted code.