Created
November 6, 2013 02:04
-
-
Save isnowfy/7329736 to your computer and use it in GitHub Desktop.
poj1007
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
using namespace std; | |
int n,m; | |
int aa(string s){ | |
int t=0; | |
for(int i=0;i<n;i++) | |
for(int j=i+1;j<n;j++) | |
if(s[i]>s[j]) | |
t++; | |
return t; | |
} | |
int main(){ | |
cin>>n>>m; | |
string a[m]; | |
int b[m]; | |
getline(cin,a[0]); | |
for(int i=0;i<m;i++){ | |
getline(cin,a[i]); | |
b[i]=aa(a[i]); | |
} | |
for(int i=0;i<m;i++) | |
for(int j=i+1;j<m;j++) | |
if(b[i]>b[j]||(b[i]==b[j]&&a[i]>a[j])){ | |
int ii=b[i]; | |
b[i]=b[j]; | |
b[j]=ii; | |
string ss=a[i]; | |
a[i]=a[j]; | |
a[j]=ss; | |
} | |
for(int i=0;i<m;i++) | |
cout<<a[i]<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment