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 qichao at 2009-07-29 17:43:00 on Problem 1002
#include<stdio.h>
#include<string.h>

void Shellsort(char R[][10],long n)
{
	long i,j,k;
	k=n/2;
	while(k>=1)
	{
		for(i=k+1;i<=n;i++)
		{
			strcpy(R[0],R[i]);
			j=i-k;
			while(strcmp(R[j],R[0])>0&&(j>=0))
			{
				strcpy(R[j+k],R[j]);
				j=j-k;
			}
			strcpy(R[j+k],R[0]);
		}
		k=k/2;
	}
}

int main()
{
	long n,i,j,k,leng;
	char ch[50],num[50],ccc[100001][10];
	int flag;
	scanf("%ld",&n);
	getchar();
	for(i=1;i<=n;i++)
	{
		gets(ch);/*输入字符串*/
		leng=strlen(ch);
		for(j=0,k=0;j<leng;j++)/*提取ch中有用字符到num中,然后再复制到ccc中*/
		{
			switch(ch[j])
			{
				case 'A':
				case 'B':
				case 'C':  num[k++]='2';   break;
				case 'D':
				case 'E':
				case 'F':  num[k++]='3';   break;
				case 'G':
				case 'H':
				case 'I':  num[k++]='4';   break;
				case 'J':
				case 'K':
				case 'L':  num[k++]='5';   break;
				case 'M':
				case 'N':
				case 'O':  num[k++]='6';   break;
				case 'P':
				case 'R':
				case 'S':  num[k++]='7';   break;
				case 'T':
				case 'U':
				case 'V':  num[k++]='8';   break;
				case 'W':
				case 'X':
				case 'Y':  num[k++]='9';   break;
				case '-':  break;
				default:   num[k++]=ch[j]; break;
			}
			if(k==3)/*在num[3]处放一个'-'*/
				num[k++]='-';
		}
		num[k]='\0';
		strcpy(ccc[i],num);
	}

	Shellsort(ccc,n);/*对ccc中的元素进行希尔排序*/

	flag=0;
	for(i=1;i<=n;i=j)
	{
		for(j=i+1;j<=n;j++)/*找到ccc[i]后第一个与ccc[i]不同的元素ccc[j]*/
		{
			if(strcmp(ccc[j],ccc[i])!=0)
				break;
		}
		if(j-i!=1)/*ccc[i]与ccc[j]不相邻时,输出ccc[i]以及它的个数j-i*/
		{
			printf("%s %d\n",ccc[i],j-i);
			flag=1;
		}
	}
	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