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 songyy at 2010-11-26 03:14:39 on Problem 1002
如题。但如果你用的 getchar()请求输入,则不存在这个问题。

我没用搜索方法,1000Ms,还是过啦:)
直接建个超大的数组进行查找的……很流氓


#include <stdio.h>
#include <string.h>
#define MAX 10000000

int trans_c(char c){
	char search[]=   "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	char corespond[]="222333444555666777788899990123456789";
	int pos=strchr(search,c)-search;
	return (pos>=0)?corespond[pos]-'0':-1;
}

long trans(char s[]){
	int n=strlen(s);
	int res=0,t,i;
	for(i=0;i<n;i++)
	{
		t=trans_c(s[i]);
		if(t==-1)	continue;
		else
		{
			res*=10;
			res+=t;
		}
	}
	return res;
}

void output(int tel[], long i)
{
	int first=i/10000, second=i%10000;
	printf("%03d-%04d %d\n",first,second,tel[i]);
}

	int tel[MAX]={};

main(){
	long i;

	int n;
	char hold[200];
	int dec=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",hold);
		tel[trans(hold)]++;
	}
	
	for(i=0;i<MAX;i++)	if(tel[i]>1){	output(tel,i);dec=1;}
	
	if(!dec)	printf("No duplicates.");
	
	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