Source Code
Problem: 1016 | User: cug_fish2008 | |
Memory: 264K | Time: 16MS | |
Language: C++ | Result: Accepted |
- Source Code
#include <iostream> using namespace std; void change(char c[],char p[]); bool cpre(char x[],char y[]); int main() { char ch[100]; while(cin>>ch && ch[0]!='-'){ for(int i=0;ch[i]!=0;i++) cout<<ch[i]; char y[15][100]; change(ch,y[0]); if(cpre(ch,y[0])){ cout<<" is self-inventorying"<<endl; continue;} int i; int u=1; strcpy(y[1],y[0]); strcpy(y[0],ch); for(i=2;i<=15;i++){ char self[100]; change(y[u],self); if(cpre(y[u],self)){ cout<<" is self-inventorying after " <<i-1<<" steps"<<endl; break;} bool b=false; for(int j=0;j<u;j++){ if(cpre(y[j],self)){ cout<<" enters an inventory loop of length " <<i-j<<endl; b=true;}} if(b)break; strcpy(y[++u],self); } if(i>15)cout<<" can not be classified after 15 iterations"<<endl; } return 0; } void change(char c[],char p[]) { int x[10]={0}; for(int i=0;c[i]!=0;i++) x[c[i]-'0']++; int u=-1; for(int i=0;i<10;i++){ if(x[i]!=0){ int t=x[i]; while(t){ p[++u]=t%10+'0'; t=int(t*0.1);} p[++u]=i+'0'; } } p[++u]=0; } bool cpre(char x[],char y[]) { int i; bool b=false; for(i=0;x[i]!=0 || y[i]!=0;i++){ if(x[i]!=y[i]){b=true;break;}} if(b)return false; return true; }