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:代码

Posted by chenxuan123456789 at 2012-07-28 09:07:07 on Problem 1002
In Reply To:代码 Posted by:chenxuan123456789 at 2012-07-28 09:06:59
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 100000+10
char hash[27]="22233344455566670778889990";
int cmp(const void *_a,const void *_b)
{
	char *a=(char*)_a;
	char *b=(char*)_b;
	return strcmp(a,b);
}
char str[M][20];
int main()
{
	int n,i,j,ans,k,flag,length;
	char s[20];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",str[i]);
		length=strlen(str[i]);
		k=0;
		for(j=0;j<length;j++)
		{
			if(str[i][j]>='A'&&str[i][j]<='Z')
				s[k++]=hash[str[i][j]-'A'];
			else
				if(str[i][j]>='0'&&str[i][j]<='9')
					s[k++]=str[i][j];
				else
					if(str[i][j]=='-');
		}
		s[k]='\0';
		strcpy(str[i],s);
	}
	qsort(str,n,sizeof(str[0]),cmp);
	flag=0;
	for(i=0;i<n;)
	{
		ans=1;
		for(j=i+1;j<n;j++)
		if(strcmp(str[i],str[j])==0)
		ans++;
		else
		break;
			if(ans>1)
			{
				flag=1;
				for(k=0;k<3;k++)
				printf("%c",str[i][k]);
				printf("-");
				for(k=3;k<7;k++)
				printf("%c",str[i][k]);
				printf(" %d\n",ans);
			}
			i+=ans;
	}
	if(!flag)
	printf("No duplicates.");
	return 1;
}





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