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

标程:

Posted by jinjinjin at 2011-06-10 20:35:36 on Problem 1007
In Reply To:怎麼會WA呢?? Posted by:wangjifeng1 at 2011-06-10 20:31:26
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
struct DNA
{
 string str;
 long int number;
};
bool myComp( const DNA &d1, const DNA &d2 )
{
 if(d1.number!=d2.number)
  return d1.number<d2.number;
 else
  return d1.str<d2.str;
}

long int calNumber( char ch[], int n )
{
 long int count=0;
 int i,j;
 for( i=0; i<n-1; i++ )
  for( j=i+1; j<n; j++ )
  {
   if( ch[i]>ch[j] )
   {
    count++;
   }
  }
 return count;
}
int main()
{
// ifstream cin("test.txt");
 vector<DNA> dna;
 int n,m;
 char ch[51];
 int i;
 cin>> n>>m ;
 dna.clear();
 cin.getline(ch,51,'\n'); 
 for( i=0; i<m; i++ )
 {
  cin.getline(ch,51,'\n'); 
  DNA nd;
  nd.number=calNumber(ch,n);
  nd.str = ch;
  dna.push_back(nd);
 }
 sort(dna.begin(), dna.end(),myComp);
 vector<DNA>::iterator it;
 for(it=dna.begin(); it!=dna.end(); it++ )
 {
  cout<<(*it).str<<endl;
 }
 return 0;
}
程序很清楚,不解释了!

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