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

Re:排序时用快速排序可能会快些,库函数中有qsort

Posted by Seraph_fd at 2010-12-16 09:22:28 on Problem 1002
In 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:
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