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:不要用字符来比较....一读入就转成long保存....可以试试用hash来记录,再选其中大于2的出来排序

Posted by ArXoR at 2005-03-24 23:16:05 on Problem 1002
In Reply To:天啊!怎么还超时!折腾了不是多长时间了!谁来看看,帮帮忙! Posted by:00 at 2005-03-24 23:12:53
> #include<stdio.h>
> #include<string.h>
> #include<stdlib.h>
> int sort(const void *,const void *);
> char tel[100000][16],Tel[100000][16];
> long *time,*c;
> long t,i,j,k,l,z=0;
> void main()
> {
> 	scanf("%d",&t);
> 	time=new long[t];
> 	c=new long[t];
> 	for(i=0;i<t;i++)
> 	{
> 		scanf("%s",tel[i]);
> 		c[i]=0;
> 		for(j=0;j<(int)strlen(tel[i]);j++)
> 		{
> 			if(tel[i][j]<81&&tel[i][j]>64)
> 				tel[i][j]=char(int((tel[i][j]-'A'+1)/3.1)+50);
> 			if(tel[i][j]>81)
> 				tel[i][j]=char(int((tel[i][j]-'A')/3.1)+50);
> 		}
> 		l=0;
> 		for(k=0;l<8;k++)
> 		{
> 			if(l==3)
> 			{
> 				Tel[i][l]='-';
> 				l++;
> 				k--;
> 				continue;
> 			}
> 			if(tel[i][k]!='-')
> 			{
> 				Tel[i][l]=tel[i][k];
> 				l++;
> 			}
> 		}
> 	}
> 	qsort(Tel,t,sizeof(Tel[0]),sort);
> 	for(i=0;i<t;i++)
> 	{
> 		for(k=0;k<t;k++)
> 		{
> 			if(!strcmp(Tel[i],Tel[k]))
> 				c[i]++;
> 		}
> 		for(j=0;j<i;j++)
> 		{
> 			if(!strcmp(Tel[j],Tel[i]))
> 				goto loop;
> 		}
> 		if(c[i]>1)
> 		{
> 			z++;
> 			printf("%s %d\n",Tel[i],c[i]);
> 		}
> loop:	i++;
> 		i--;
> 	}
> 	if(!z)
> 		printf("%s\n","No duplicates.");
> 	delete [] time;
> 	delete [] c;
> }
> int sort(const void *a, const void *b)
> {
> 	return (strcmp((char*)a,(char*)b));
> }

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