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 asdsas at 2008-04-09 16:45:06 on Problem 1002
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define SIZE 100010
char tel[SIZE][8];
	int n;
int comp(const void *elem1,const void *elem2)
{
	return (strcmp((char *)elem1,(char *)elem2));
}
void print(int i)
{
	int j;
	for(j=0;j<3;j++)
	{
		printf("%c",tel[i][j]);
	}
	printf("-");
	for(j=3;j<8;j++)
	{
		printf("%c",tel[i][j]);
	}
}
void find()
{
	/*int i,j,k;
	int flag=0;
	k=0;
	for(i=0;i<n-1;i++)
	{
		
		if(!strcmp(tel[i],tel[i+1]))
		{
			k++;
		}
		else if(k!=0)
		{
			print(i);
			printf(" %d\n",k+1);

			flag=1;
			k=0;
		}
		

	}
	if(k!=0)
	{
		print(i-1);
			printf(" %d\n",k+1);
			flag=1;
			k=0;
	}
	if(!flag)
	{
		printf("No duplicates.\n");
	}*/
	int nod=0;
	int i=0;
	int j;
	while(i<n)
	{
		j=i;
		i++;
		while(i<n&&(!strcmp(tel[i],tel[j]))) i++;
		if(i-j>1)
		{
			print(j);
			printf(" %d\n",i-j);
			nod=1;
		}
	}
	if(!nod)
	{
		printf("No duplicates.\n");
	}
}
int main()
{
	char stemp[150];

	int i,j,k;
	int l;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",stemp);
		l=strlen(stemp);
		k=-1;
		for(j=0;j<l;j++)
		{
			if(stemp[j]>='0'&&stemp[j]<='9')
			{
				k++;
				tel[i][k]=stemp[j];
			}
			else if(stemp[j]>='A'&&stemp[j]<='C')
			{
				k++;
				tel[i][k]='2';
			}
			else if(stemp[j]>='D'&&stemp[j]<='F')
			{
				k++;
				tel[i][k]='3';
			}
			else if(stemp[j]>='G'&&stemp[j]<='I')
			{
				k++;
				tel[i][k]='4';
			}
			else if(stemp[j]>='J'&&stemp[j]<='L')
			{
				k++;
				tel[i][k]='5';
			}
			else if(stemp[j]>='M'&&stemp[j]<='O')
			{
				k++;
				tel[i][k]='6';
			}
			else if(stemp[j]>='P'&&stemp[j]<='S'&&(stemp[j]!='Q'))
			{
				k++;
				tel[i][k]='7';
			}
			else if(stemp[j]>='T'&&stemp[j]<='V')
			{
				k++;
				tel[i][k]='8';
			}
			else if(stemp[j]>='W'&&stemp[j]<='Y')
			{
				k++;
				tel[i][k]='9';
			}
		}
		tel[i][k+1]=0;
	}

	qsort(tel,n,8,comp);
	find();
	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