View Code of Problem 126

#include<bits/stdc++.h>
using namespace std;
#define max 100	
int jud(string s,int n);
int main(){     
	int n,m,a[max] = { },op,we = 0;
	string s[max];
	while(scanf("%d%d",&n,&m)!=EOF){     
		getchar();
		for(int j = 0;j < m ;j++){      //一共执行m次 
		  	getline(cin,s[j]);
		  	op = jud(s[j],n);
			a[j] = op;	
		}    
//		for(int i = 0;i<m;i++)cout<<a[i]<<" ";
		
		
		for(int i = 0;i<m;i++){
			int min = 100000, k = 0;
			for(int j = 0;j < m;j++){
				if(a[j]<min &&a[j]!=-1){
					min = a[j];
					k = j;
			}
		}
		cout<<s[k]<<endl;
		a[k] = -1;
	}
			
	}
		
	
	return 0;
}  
int jud(string s,int n){
	char c;
	int num = 0;
	for(int i = 0;i<n;i++){
		c = s[i];
		for(int j = i;j<n;j++){
			if(c <= s[j])continue;
			else num++;
		}
	}	
	return num;
}





Double click to view unformatted code.


Back to problem 126