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 497597816 at 2007-06-13 20:40:00 on Problem 1002
#include "stdio.h"
#include "string.h"
struct {
int h,l,t,ne;
}s[100000];
int h[100000]={0};
int l[100000]={0};
char da[100000][25];
int main() {
 	int n,i,j,p,f,b,d,u;
	char c;
	scanf("%d",&n);
	for(j=0;j<n;j++)scanf("%s",da[j]);
	for(j=0;j<n;j++){
	u=strlen(da[j]);
	d=b=0;
	for(i=0;i<u;i++){
		c=da[j][i];
	  if(c!='-'){
		if(c>='0'&&c<='9')p=c-'0';
		else if(c>='A'&&c<='Y')p=(c<'Q'?(c-'A'):(c-'B'))/3+2;
		if(b==7)break;
		if(b<=3){h[j]=h[j]*10+p;b++;}
		else {l[j]=l[j]*10+p;b++;}
	  }
	}
	}
	s[0].h=s[0].l=s[0].ne=-1;
	s[0].t=0;
	j=1;
	for(i=0;i<n;i++){
	f=p=0;
	d=h[i]*10000+l[i];
	while(s[p].ne!=-1&&d>(s[p].h*10000+s[p].l)){f=p;p=s[p].ne;}
	if(d==(s[p].h*10000+s[p].l))s[p].t++;
	else	if(d<(s[p].h*10000+s[p].l))
	{
		s[j].h=h[i];
		s[j].l=l[i];
		s[j].t=1;
		s[j].ne=p;
		s[f].ne=j;
		j++;
	}
	else{
		s[j].h=h[i];
		s[j].l=l[i];
		s[j].t=1;
		s[j].ne=s[p].ne;
		s[p].ne=j;
		j++;
	}
	}
	b=p=0;
	while(s[p].ne!=-1)
	{
		if(s[s[p].ne].t>1)
		{	printf("%03d-%04d %d\n",s[s[p].ne].h,s[s[p].ne].l,s[s[p].ne].t);
			b=1;
		}
			p=s[p].ne;
	}
	if(b==0)printf("No duplicates.\n");
	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