afterward

导航

 
View Code
#include <iostream>
#include <algorithm>
using namespace std;

class DNA
{
public:
char DNAString[51];
int length;
int measure;
DNA()
{
   length=0;
   measure=0;
}
DNA(const DNA &a )
{
   length=a.length;
   measure=a.measure;
   for (int i=0;i<length;++i )
    DNAString[i]=a.DNAString[i];
   DNAString[length]='\0';
}
void calMeasure()
{
   measure;
   for (int i=0;i<length;++i )
    for (int j=i+1;j<length;++j )
     if (DNAString[i]>DNAString[j])
      ++measure;
}
static bool comp(const DNA *a,const DNA *b )
{
   return a->measure<b->measure;
}
};

int main()
{
DNA* items[100];
int number,length;
while ( cin>>length>> number )
{
   int i;
   for ( i=0;i<number;++i ){
    items[i]=new DNA();
    cin>>items[i]->DNAString;
    items[i]->length=length;
    items[i]->calMeasure();
   }

   sort(items,items+number,DNA::comp );
   for (i=0;i<number;++i ){
    cout<<items[i]->DNAString<< endl;
    delete items[i];
   }
}
return 0;
}

有时候别人的代码就是比自己的好,到位啊!先保留着。

posted on 2012-08-02 20:49  afterward  阅读(113)  评论(0编辑  收藏  举报