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 HTF at 2006-03-30 22:39:21 on Problem 1002
#include<stdio.h>
#define   N  	50000
#define	  TRUE	1
#define   FALSE	0

short s[]={0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1};

int main()
{
	int	i, j, k,m;
	int 	n, flag;
    	int	t[N];
	char	tel2[30];
	char	index;
	unsigned long  	tel[N];
	unsigned long	temp;

	for (i=0; i<N; i++)
		t[i] = 0;
	k = 0;
	scanf("%d", &n);
	for (i=0; i<n; i++)
	{
		temp = 0;
		scanf("%s", tel2);
		for (j=0; tel2[j]!='\0'; j++)        /*化为长整型数*/
		{
			index = tel2[j];
			if (index != '-')
				temp = temp * 10 + s[index - '0'];
		}
		for (j=k-1; j>=0; j--)     /*如果之前已记录此数,则其个数加一*/
		{
			if (temp == tel[j])
			{
				t[j]++;
				break;
			}
		}
		if (j < 0)
		{
			tel[k] = temp;   /*之前数组中无此数,则在最末加入此数,计数加一*/
			t[k]++;
			k++;
		}
	}
	m = k-1;  /*排序*/
	for (i=0; i<=m-1; i++)
	{
		k = i;
		for (j=i+1; j<=m; j++)
			if (tel[j] < tel[k])	k = j;
		if (k != i)
		{
			temp = tel[k];
			tel[k] = tel[i];
			tel[i] = temp;
		}
	}

	flag = FALSE;
	for (j=0; j<=m; j++)
		if (t[j] >= 2)
		{
			printf("%0.3ld-%0.4ld %d\n", tel[j]/10000,tel[j]%10000,t[j]);
			flag = TRUE;
		}
	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