View Code of Problem 126

#include<iostream>
using namespace std;
int main(void){
	int n,m;
	while(cin>>n>>m){
		string s[100];
		int v[100]={0};
		for(int i=0;i<m;i++){
			cin>>s[i];
			int sum=0;
			for(int j=0;j<n;j++){
				for(int l=j+1;l<n;l++){
					if(s[i][j]>s[i][l]) 
						v[i]++;
				}
			}
		}
		for(int i=0;i<m;i++){
			int min=1050,k;
			for(int j=0;j<m;j++){
				if(min>v[j]&&v[j]!=-1){
					min=v[j];
					k=j;
				}
			}
			cout<<s[k]<<endl;
			v[k]=-1;
		}
	}	
}

Double click to view unformatted code.


Back to problem 126