| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
奇怪,为什么RUNTIME ERROR呢,我在自己的机器上好好的啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator