#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string input;
string temp;
string output;
int visit[10];
string HH[16];
int Loop(int k,string s){
int i;
for(i=0;i<k;i++)
if(HH[i]==s)
return i;
}
return -1;
}
int main(){
inti,j,k;
while(1){
cin>>input;
if(input=="-1")
break;
temp=input;
HH[0]=input;
for(k=1;k<=15;k++){
memset(visit,0,sizeof(visit));
output="";
i=0;
while(temp[i]!='\0'){
visit[temp[i]-'0']++;
i++;
}
for(j=0;j<10;j++){
char v='0'+j;
if(visit[j]>=10){
chart1='0'+visit[j]/10;
chart2='0'+visit[j]%10;
output=output+t1+t2+v;
}
else if(visit[j]>0){
chart3='0'+visit[j];
output=output+t3+v;
}
}
HH[k]=output;
if(output==temp&&k==1){
cout<<input<<" is self-inventorying"<<endl;
break;
}
else if(output==temp&&k!=1){
cout<<input<<" is self-inventorying after "<<k-1<<"steps"<<endl;
break;
}
else if(Loop(k,output)>=0){
cout<<input<<" enters an inventory loop of length "<<k-Loop(k,output)<<endl;
break;
}
else{
temp=output;
}
}
if(k>15){
cout<<input<<" can not be classified after 15 iterations"<<endl;
}
}
return0;
}
网友评论