| ||||||||||
| 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 | |||||||||
Re:同志们,帮我看看错在哪里,谢谢!In Reply To:同志们,帮我看看错在哪里,谢谢! Posted by:LongBear at 2008-05-23 19:22:33 #include <iostream>
#include <string>
using namespace std;
class DNA
{
public:
DNA (){ left=NULL;right=NULL;}
int n;
string str;
DNA * left;
DNA * right;
};
void insert(DNA *,DNA *);
void type(DNA *);
int fy(string);
int main()
{
DNA *head=new DNA();
int n,m;
cin>>n>>m;
int i;
cin>>head->str;
head->n=fy(head->str);
for(i=0;i<m-1;i++)
{
DNA *next=new DNA();
cin>>next->str;
next->n=fy(next->str);
insert(head,next);
}
type(head);
return 0;
}
int fy(string str)
{
int temp=0;
int i,j;
int n=str.length();
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(str[i]>str[j]) temp++;
return temp;
}
void insert(DNA *first,DNA * nt)
{
if( (first->n) <( nt->n) )
{
if(first->right==NULL) first->right=nt;
else insert(first->right,nt);
} else
{
if(first->left==NULL) first->left=nt;
else insert(first->left,nt);
}
}
void type(DNA * head)
{
if(head->left!=NULL)
type(head->left);
cout<<head->str<<endl;
if(head->right!=NULL) type(head->right);
}
弄好了自己,太粗心了刚刚。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator