| ||||||||||
| 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:排序时用快速排序可能会快些,库函数中有qsortIn Reply To:Re:排序时用快速排序可能会快些,库函数中有qsort Posted by:tangson at 2010-11-18 19:59:48 哪个库……
那个qsort是怎么实现的呢?
我最近改了改,直接是wrong answer了……郁闷。
#include <iostream>
using namespace std;
int k=0;
typedef struct node
{
int N;
int count;
struct node *L;
struct node *R;
}NODE,*Node;
int main()
{
void Insert(Node head,int N);
void Print(Node H);
Node H;
long i=0,j=0,k,x;
char c;
H=new NODE;
H->L=NULL;
H->R=NULL;
H->N=0;
cin>>x;
x=x*7;
while(i<x)
{
cin>>c;
if(c=='-')
continue;
else if('0'<=c&&c<='9')
k=c-'0';
else if('A'<=c&&c<'Q')
k=(c-';')/3;
else
k=(c-'<')/3;
j=j*10+k;
i++;
if(i%7==0)
{
Insert(H,j);
j=0;
}
}
cout<<endl;
Print(H->R);
if(!k)
cout<<"No duplicates."<<endl;
return 0;
}
void Insert(Node head,int N)
{
Node p,q;
p=head;
q=new NODE;
q->L=NULL;
q->R=NULL;
q->count=0;
q->N=N;
while(N!=p->N&&p!=NULL)
if(N>p->N)
if(p->R==NULL)
{
p->R=q;
break;
}
else
p=p->R;
else if(N<p->N)
if(p->L==NULL)
{
p->L=q;
break;
}
else
p=p->L;
if(p->N==N)
{
p->count++;
delete q;
}
}
void Print(Node H)
{
if(H->L!=NULL)
Print(H->L);
if(H->count)
{
if(H->N>999999)
cout<<H->N/10000;
else
{
cout<<H->N/1000000;
cout<<(H->N%1000000)/100000;
cout<<(H->N%100000)/10000;
}
cout<<'-';
if(H->N%1000>999)
cout<<H->N%10000;
else
{
cout<<(H->N%10000)/1000;
cout<<(H->N%1000)/100;
cout<<(H->N%100)/10;
cout<<H->N%10;
}
cout<<' '<<H->count+1<<'\n';
k++;
}
if(H->R!=NULL)
Print(H->R);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator