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

求大神分析一下runtime error 的原因,才开始做,没经验!不胜感激。。。

Posted by 21090922 at 2012-07-28 15:34:18 on Problem 1002
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char map[] = "22233344455566677778889999";	//字母转化成数字
char str[50];	//读入的号码
char tel[10000][9];	//标准的号码

//标准函数sort()的比较条件
int compare ( const void* elem1, const void* elem2 )
{
	return strcmp( (char*)elem1, (char*)elem2 );
}

//好记的号码转化为标准的号码
void standardizeTel ( int n )
{
	int k = 0;
	for ( int i = 0; str[i] != EOF; i++ )
	{
		if (str[i] == '-')
		{
			continue;
		}
		if ( k == 3 )
		{
			tel[n][k++] = '-';
		}
		if ( str[i] >= 'A' && str[i] <= 'Z')
		{
			tel[n][k++] = map[ str[i] - 'A' ];
			continue;
		}
		tel[n][k++] = str[i];
	}
	tel[n][k] = '\0';
}

int main ()
{
	int n;	//号码的数量
	scanf ( "%d", &n );
	for ( int i = 0; i < n; i++ )	//输入n个号码并标准化
	{
		scanf ( "%s", str );
		standardizeTel ( i );
	}
	qsort ( tel, n, 9, compare );	//字典排序
	bool duplicate = true;
	int j , k = 0;
	while ( k < n )
	{
		j = k;
		k++;
		while ( (strcmp ( tel[j], tel[k] ) == 0) && (k < n) ) 
		{
			k++;
		}
		if( k - j > 1)
		{
			duplicate = false;
			printf ( "%s %d\n", tel[j], (k - j) );
		}
	}
	if ( duplicate )
	{
		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