Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用map做的应该还满容易理解的

Posted by foreverlin at 2008-11-13 08:54:11 on Problem 1007
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator