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 hongqin at 2005-11-10 13:34:46 on Problem 1016
#include"stdio.h"
#include"string.h"
void sort(char *b)
{
	char c;
	int n,i,j;
	n=strlen(b);
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
			if(b[i]>b[j])
			{
				c=b[i];
				b[i]=b[j];
				b[j]=c;
			}
	}
}
void change(char *p,char *q)
{
	char c,s;
	int n,i,j,left,right,count=1;
	c=p[0];
	n=strlen(p);
	for(i=1,j=0;i<=n;i++)
	{
		if(p[i]==c)
			count++;
		else
		{
			left=count/10;
			right=count%10;
			if(left)
			{
				s='0'+left;
				q[j++]=s;
			}
			s='0'+right;
			q[j++]=s;
			q[j++]=c;
			c=p[i];
			count=1;
		}
	}
	q[j]='\0';
}
void main()
{
	char a[100][200];
	int i=0,j,k,h,count;
	while(1)
	{
		scanf("%s",a[i++]);
		if(a[i-1][0]=='-'&&a[i-1][1]=='1')
		break;
	}
	for(j=0;j<i-1;j++)
	{
		k=i;
		strcpy(a[k],a[j]);
		for(count=0;count<15;count++)
		{
			strcpy(a[i-1],a[k]);
			sort(a[i-1]);
			strcpy(a[++k],"  ");
			change(a[i-1],a[k]);
			if(!count&&!strcmp(a[i],a[k]))
			{
				printf("%s is self-inventorying\n",a[j]);
				break;
			}
			else
			{
				for(h=i;h<=k&&strcmp(a[h],a[k]);h++);
				if(h==k)
					continue;
				if(h==k-1)
				{
					printf("%s is self-inventorying after %d steps\n",a[j],count);
					break;
				}
				else
				{
					printf("%s enters an inventory loop of length %d\n",a[j],k-h);
					break;
				}
			}
		}
		if(count==15)
			printf("%s can not be classified after 15 iterations\n",a[j]);
	}
}


		
	







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