View Code of Problem 126

#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,n,t;
	while(scanf("%d %d",&m,&n)!=EOF){
		string s;
		map<int,vector<string>> op;
		for(int i=0;i<n;i++){
			cin>>s;
			int u=0;
			for(int j=0;j<m;j++){
				for(int g=j;g<m;g++){
					if(s[j]>s[g]){
						u++;
					}
				}
			}
			op[u].push_back(s);
		}
		for(auto i=op.begin();i!=op.end();i++){
			for(int j=0;j<(i->second).size();j++){
				cout<<(i->second)[j]<<endl;
			}
			
		}	
	}	
}

Double click to view unformatted code.


Back to problem 126