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

Time Limit Exceed!牛人们!帮帮忙!

Posted by 00 at 2005-03-23 18:21:55 on Problem 1002
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void analyse();
void change();
void countTel();
int sort(const void *a,const void *b);
char telNum[100000][15],TelNum[100000][15];
int *time,*count;
long t,i,j,k,l;
void main()
{
	scanf("%d",&t);
	time=new int[t];
	count=new int[t];
	for(i=0;i<t;i++)
	{
		scanf("%s",telNum[i]);
		count[i]=0;
		analyse();
		change();
	}
	qsort((void *)TelNum,t,15,sort);
	for(i=0;i<t;i++)
		countTel();
	for(i=0;i<t;i++)
	{
		for(j=0;j<i;j++)
		{
			if(!strcmp(TelNum[j],TelNum[i]))
				goto loop;
		}
		if(count[i]>1)
			printf("%8s %d\n",TelNum[i],count[i]);
loop:	i++;
		i--;
	}
	delete [] time;
	delete [] count;
}
void analyse()
{
	for(j=0;j<(int)strlen(telNum[i]);j++)
	{
		if(telNum[i][j]=='A'||telNum[i][j]=='B'||telNum[i][j]=='C')
			telNum[i][j]='2';
		if(telNum[i][j]=='D'||telNum[i][j]=='E'||telNum[i][j]=='F')
			telNum[i][j]='3';
		if(telNum[i][j]=='G'||telNum[i][j]=='H'||telNum[i][j]=='I')
			telNum[i][j]='4';
		if(telNum[i][j]=='J'||telNum[i][j]=='K'||telNum[i][j]=='L')
			telNum[i][j]='5';
		if(telNum[i][j]=='M'||telNum[i][j]=='N'||telNum[i][j]=='O')
			telNum[i][j]='6';
		if(telNum[i][j]=='P'||telNum[i][j]=='R'||telNum[i][j]=='S')
			telNum[i][j]='7';
		if(telNum[i][j]=='T'||telNum[i][j]=='U'||telNum[i][j]=='V')
			telNum[i][j]='8';
		if(telNum[i][j]=='W'||telNum[i][j]=='X'||telNum[i][j]=='Y')
			telNum[i][j]='9';
	}
}
void change()
{
	for(j=0;j<t;j++)
	{
		l=0;
		for(k=0;l<8;k++)
		{
			if(l==3)
			{
				TelNum[j][l]='-';
				l++;
				k--;
				continue;
			}
			if(telNum[j][k]!='-')
			{
				TelNum[j][l]=telNum[j][k];
				l++;
			}
		}
	}
}
int sort(const void *a, const void *b)
{
	return (strcmp((char*)a,(char*)b)); 
}
void countTel()
{
	for(j=0;j<t;j++)
	{
		if(count[j]!=0)
			break;
		for(k=0;k<t;k++)
		{
			if(!strcmp(TelNum[j],TelNum[k]))
				count[j]++;
		}
	}
}

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