| ||||||||||
| 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 | |||||||||
求你帮帮忙,我哪个数据通不过!万分感谢!#include <iostream.h>
#include <string.h>
char a[100];
int gs[10];
char b[17][39];
char c;
int w,k,leng,ok=0;
void deal(int i)
{
int q,l,j=0;
l=strlen(b[i]);
for(q=0;q<10;q++)
gs[q]=0;
for(q=0;q<l;q++)
gs[(int)b[i][q]-48]++;
for(q=0;q<10;q++)
{
if(gs[q]==0)
continue;
if(gs[q]<10)
{
b[i+1][j]=(char)(gs[q]+48);
j++;
b[i+1][j]=(char)(q+48);
j++;
}
else
{
b[i+1][j]=(char)(gs[q]/10+48);
j++;
b[i+1][j]=(char)(gs[q]%10+48);
j++;
b[i+1][j]=(char)(q+48);
}
}
}
void main()
{
cin>>a;
while(a[0]!='-')
{
ok=0;
for(w=0;w<10;w++)
gs[w]=0;
for(w=0;w<=16;w++)
strcpy(b[w],"");
for(w=0;w<=16;w++)
for(k=0;k<39;k++)
b[w][k]=c;
k=0;
leng=strlen(a);
for(w=0;w<leng;w++)
gs[(int)(a[w]-48)]++;
for(w=0;w<10;w++)
{
if(gs[w]==0)
continue;
if(gs[w]<10)
{
b[1][k]=(char)(gs[w]+48);
k++;
b[1][k]=(char)(w+48);
k++;
}
else
{
b[1][k]=(char)(gs[w]/10+48);
k++;
b[1][k]=(char)(gs[w]%10+48);
k++;
b[1][k]=(char)(w+48);
k++;
}
}
cout<<a;
if(strcmp(b[1],a)==0)
{
cout<<" is self-inventorying"<<endl;ok=1;
}
else
{
for(w=1;w<=14;w++)
{
deal(w);
if(strcmp(b[w+1],a)==0)
{
cout<<" enters an inventory loop of length "<<w+1<<endl;ok=1;
break;
}
else
{
for(k=1;k<=w;k++)
{
if(strcmp(b[w+1],b[k])==0)
{
if(k==w)
cout<<" is self-inventorying after "<<w<<" steps"<<endl;
else
cout<<" enters an inventory loop of length "<<w+1-k<<endl;
ok=1;break;
}
}
if(ok==1)
break;
}
}
}
if(ok==0)
cout<<" can not be classified after 15 iterations"<<endl;
// for(w=1;w<=16;w++)
// if(strcmp("",b[w])!=0)
// cout<<b[w]<<endl;
cin>>a;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator