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 yiubian at 2013-06-30 14:02:49 on Problem 1002
#include <stdio.h>
#include <string.h>
char str[50];
int phone[100000];
int num[100000];

void tran(char *s,int n)
{
	int i,j;
	for(i=0,j=0;j<7;i++)
	{
	if(s[i]>='0'&&s[i]<='9')
	{
		phone[n]=phone[n]*10+s[i]-'0';
		j++;
	}
	else if(s[i]>='A'&&s[i]<'Z')
	{
	j++;
	switch(s[i])
	{
	case 'A':case 'B':case 'C':
		phone[n]=phone[n]*10+2;
		break;
	case 'D':case 'E':case 'F':
		phone[n]=phone[n]*10+3;
		break;
	case 'G':case 'H':case 'I':
		phone[n]=phone[n]*10+4;
		break;
	case 'J':case 'K':case 'L':
		phone[n]=phone[n]*10+5;
		break;
	case 'M':case 'N':case 'O':
		phone[n]=phone[n]*10+6;
		break;
	case 'P':case 'R':case 'S':
		phone[n]=phone[n]*10+7;
		break;
	case 'T':case 'U':case 'V':
		phone[n]=phone[n]*10+8;
		break;
	case 'W':case 'X':case 'Y':
		phone[n]=phone[n]*10+9;
		break;
	}
	}
	}
}

void quick_sort(int *a,int low,int heigh)
{
	int i=low,j=heigh,temp=a[low],swap=num[low];
	while(i<j)
	{
		while(i<j&&temp<=a[j]) j--;
		if(i<j)
		{
			a[i]=a[j];
			num[i]=num[j];
			i++;
		}
		while(i<j&&a[i]<temp) i++;
		if(i<j)
		{
			a[j]=a[i];
			num[j]=num[i];
			j--;
		}
	}
	a[i]=temp;
	num[i]=swap;
	if(low<i)
		quick_sort(a,low,i-1);
	if(i<heigh)
		quick_sort(a,j+1,heigh);
}
void show(int t)
{
	printf("%d-",phone[t]/10000);
	printf("%d %d\n",phone[t]%10000,num[t]);
}
int main()
{
	int sj,i,j,n=0,flag=0;
	scanf("%d",&sj);
	for(i=0;i<sj;i++)
	{
		num[i]=0;
	}
	for(i=0;i<sj;i++)
	{
		scanf("%s",&str);
		phone[n]=0;
		tran(str,n);
		num[n]=1;
		n++;
		for(j=0;j<n-1;j++)
		{
			if(phone[j]==phone[n-1])
			{
				num[j]++;
				n--;
				break;
			}
		}
	}
	quick_sort(phone,0,n-1);
	for(i=0;i<n;i++)
	{
		if(num[i]>1)
		{
			flag=1;
			show(i);
		}
	}
	if(flag==0)
		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