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

大家看看我的代码吧!总是WA.小弟在此谢过各位大牛了!

Posted by killer8888 at 2007-11-05 23:07:28 on Problem 1002
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int abc[110000];
int letter(char x)
{
	if(x>=48&&x<=57) return x-48;
	else if(x<81) return (x-65)/3+2;
	else return (x-66)/3+2;
}//将输入的电话号码变成数字码
int paixu(int *a,int n)
{
	if(n<=1) return 0;
	int low=0,high=n-1;
	int key=(a[low]+a[high]+a[(low+high)/2])/3;
	int t;
	while(low<high)
	{
		for(;a[high]>=key&&low<high;high--)
		;
		t=a[low];
		a[low]=a[high];
		a[high]=t;
		for(;a[low]<=key&&low<high;low++)
			;
		t=a[high];
		a[high]=a[low];
		a[low]=t;
	}
	paixu(a,high+1);
	paixu(a+high+1,n-high-1);
	return 0;
}//快速排序函数
int main()
{
	int i,n;
	scanf("%d",&n);
	char b[100];
	if(n==0) return 0;
	for(i=0;i<n;i++)
	{
		int c=0;
		scanf("%s",b);
		int j,k=1000000;
		for(j=0;j<strlen(b);j++)
		{			
			if(b[j]!='-')
			{
				c+=letter(b[j])*k;
				k/=10;
			}
		}
		abc[i]=c;
	}
		//对电话号码处理后储存在c中,然后转存到数组abc中。
	paixu(abc,n);//对abc数组进行排序	
	int j=1,k=0;
	for(i=1;i<n;i++)
	{
		if(abc[i]==abc[i-1])
			j++;
		else if(j>1)
		{
			k=1;
		printf("%03d-%04d %d\n",abc[i-1]/10000,abc[i-1]%10000,j);
		j=1;
		}//输出
	}	
	if(j>1)
	{
		k=1;
		printf("%03d-%04d %d\n",abc[i-1]/10000,abc[i-1]%10000,j);
	}//如果最后两个字符相同,将不会输出,所以要补上这句。	
    if(k==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