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 scy911 at 2005-07-04 13:36:56 on Problem 1016
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
char *trans(char *p)
{
	int i,j;
	int c[10]={0,0,0,0,0,0,0,0,0,0};
	char *op=new char[strlen(p)+1];
	op[0]='\0';
	for (i=0;i<strlen(p);i++)
	{
		c[p[i]-'0']++;
	}
	j=0;
	for (i=0;i<10;i++)
	if (c[i])
	{
		if (c[i]>10)
		{
			op[j++]=c[i]/10+'0';
			c[i]/=10;
		}
		op[j++]=c[i]+'0';
		op[j++]=i+'0';
	}
	op[j]='\0';
	return op;
}
void load()
{
	char inp[100],*str,old[16][100];
	int i,j,lo=0,e=0;
	cin>>inp;
	while (strcmp(inp,"-1"))
	{
		e=0;
		str=trans(inp);
		if (!strcmp(inp,str))
		{cout<<inp<<" is self-inventorying"<<endl;e=1;}
		else
		{
			for (i=0;i<15;i++)
			{
				strcpy(old[i],str);
				str=trans(str);
				if (!strcmp(old[i],str))
				{
					cout<<inp<<" is self-inventorying after "<<i+1<<" steps"<<endl;
					e=1;
					break;
				}else 
				{
					lo=0;
					for (j=0;j<=i;j++)
					{
						if (!strcmp(old[j],str))
						{
							cout<<inp<<" enters an inventory loop of length "<<i+1<<endl;
							lo=1;
							e=1;
							break;
						}
					}
					if (lo) break;
				}
			}
		}
		if (!e) cout<<inp<<" can not be classified after 15 iterations"<<endl;
		cin>>inp;
	}
}
void main()
{
	load();
}

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