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 star55 at 2004-03-26 12:47:12 on Problem 1002
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char cover(char c){
	if(c=='A'||c=='B'||c=='C') return '2';
	if(c=='D'||c=='E'||c=='F') return '3';
	if(c=='G'||c=='H'||c=='I') return '4';
	if(c=='J'||c=='K'||c=='L') return '5';
	if(c=='M'||c=='N'||c=='O') return '6';
	if(c=='P'||c=='R'||c=='S') return '7';
	if(c=='T'||c=='U'||c=='V') return '8';
	if(c=='W'||c=='X'||c=='Y') return '9';
	if(c>='0'&&c<='9') return c;
	return 0;
}

int cmp(const void * arg1,const void * arg2)
{
	return  *((int *)arg1)-*((int*)arg2);
}

int main()
{
	int n,i,j,k,a_count,r_count,len,tmp,count,flag;
	char buf[100],reg[100];
	int answer[100];

	scanf("%d",&n);
	a_count=0;
	for(i=0;i<n;i++){
		scanf("%s",buf);
		r_count=0;
		len=strlen(buf);
		for(j=0;j<len;j++){	
			if(cover(buf[j])!=0) reg[r_count++]=cover(buf[j]);
			else continue;
		}
		reg[r_count++]='\0';
		answer[a_count++]=atoi(reg);
	}

	qsort(answer,a_count,sizeof(int),cmp);
	flag=0;
	for(i=0;i<a_count;i++){
		count=0;
		if(answer[i]!=0){
			count=1;
			tmp=answer[i];
			for(j=i+1;j<a_count;j++)
				if(tmp==answer[j]){
					count++;
					flag=1;
					answer[j]=0;
				}
		}else continue;
		if(count>1){
			sprintf(buf,"%d",tmp);
			for(k=0;k<7;k++){
				if(k==3) printf("-");
				printf("%c",buf[k]);
			}
			printf(" %d\n",count);
		}
	}

	if(!flag) printf("No duplicates.\n");
	
	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