?? 1016.c
字號:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp( const void *a , const void *b )
{
return *(char *)a - *(char *)b;
}
int main()
{
char s[81],a[81],b[30][81];
int i,j,k,m,count,time;
while(scanf("%s",s),strcmp(s,"-1"))
{
time=0;
while(1)
{
for(k=0;k<time;k++)
if(strcmp(s,b[k])==0)
break;
if(k<time)
break;
strcpy(b[time],s);
m=strlen(s);
qsort(s,m,sizeof(s[0]),cmp);
for(i=j=0,count=1;i<m;i++)
if(s[i]==s[i+1])
count++;
else
{
if(count>9)
{
a[j++]=count/10+'0';
a[j++]=count%10+'0';
a[j++]=s[i];
}
else
{
a[j++]=count+'0';
a[j++]=s[i];
}
count=1;
}
a[j]='\0';
if(strcmp(b[time],a))
{
strcpy(s,a);
time++;
if(time==16)
break;
}
else
break;
}
if(time==16)
printf("%s can not be classified after 15 iterations\n",b[0]);
else if(k<time)
printf("%s enters an inventory loop of length %d\n",b[0],time-k);
else if(time==0)
printf("%s is self-inventorying\n",b[0]);
else
printf("%s is self-inventorying after %d steps\n",b[0],time);
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -