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 youhuang at 2012-04-06 22:53:59 on Problem 1002
#include"stdio.h"
#include"string.h"
#include"math.h"
#include"stdlib.h"


//转为标准形式
void standard(char *s)
{
	int n,i,j;
	char ch,c[100];
	n=strlen(s);
	j=0;
	for(i=0;i<n;i++)
	{
		if(s[i]>='0'&&s[i]<='9'||s[i]>='A'&&s[i]<='Z')
		{
			ch=s[i];
			if(ch=='A'||ch=='B'||ch=='C')
				ch='2';
			else if(ch=='D'||ch=='E'||ch=='F')
				ch='3';
			else if(ch=='G'||ch=='H'||ch=='I')
				ch='4';
			else if(ch=='J'||ch=='K'||ch=='L')
				ch='5';
			else if(ch=='M'||ch=='N'||ch=='O')
				ch='6';
			else if(ch=='P'||ch=='R'||ch=='S')
				ch='7';
			else if(ch=='T'||ch=='U'||ch=='V')
				ch='8';
			else if(ch=='W'||ch=='X'||ch=='Y')
				ch='9';
			if(j==3)
			{
				c[j]='-';
				j++;
			}
			c[j]=ch;j++;
		}
	}
	c[j]='\0';
	strcpy(s,c);
}


main()
{
	int n,i,j,a[100],k,flag,b;
	char s[100][100],c[100][100],ch[100];
	scanf("%d\n",&n);
	memset(a,0,sizeof(a));
	for(i=0;i<n;i++)
	{
		gets(s[i]);
		standard(s[i]);
	}
	k=0;
	strcpy(c[0],s[0]);
	a[0]++;
	for(i=1;i<n;i++)
	{
		flag=0;
		for(j=0;j<=k;j++)
		{
			if(strcmp(c[j],s[i])==0)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			a[j]++;
		}
		else
		{
			k++;
			strcpy(c[k],s[i]);
			a[k]++;
		}
	}


	//排序
	for(i=0;i<k;i++)
	{
		flag=0;
		for(j=0;j<k-i;j++)
		{
			if(strcmp(c[j+1],c[j])<0)
			{
				strcpy(ch,c[j]);
				strcpy(c[j],c[j+1]);
				strcpy(c[j+1],ch);
				b=a[j];
				a[j]=a[j+1];
				a[j+1]=b;
				flag=1;
			}
		}
		if(flag==0)
			break;
	}

	flag=0;
	for(i=0;i<=k;i++)
	{
		if(a[i]>=2)
		{
		printf("%s %d\n",c[i],a[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