Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用map做的应该还满容易理解的#include<iostream> #include<string> #include<algorithm> #include<map> using namespace std; //就是求逆序数,然后按从小到大输出即可 int main() { int n,m,i,j,k,len; string s; while(cin>>n>>m) { map<int,string>ma; int a[m+1]; memset(a,0,sizeof(a)); for(i=0;i<m;i++) { cin>>s; len=s.length(); for(j=0;j<len;j++) { for(k=j+1;k<len;k++) { if(s[j]>s[k])a[i]++; } } ma[a[i]]=s; } sort(a,a+m); for(i=0;i<m;i++) { cout<<ma[a[i]]<<endl; } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator