| ||||||||||
| 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"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][81];
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(!strcmp(a[i],a[k])&&!count)
{
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 if(h<k-1)
{
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator