| ||||||||||
| 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>
#include<string>
#include<memory>
using namespace std;
char next[100];
char n[100];
void generate_next(char str[])
{
int i;
int count[10];
memset(count,0,sizeof(count));
int k=0;
int len=strlen(str);
for(i=0;i<len;i++)
count[str[i]-'0']++;
for(i=0;i<10;i++)
if(count[i]>0&&count[i]<10)
{
next[k++]=count[i]+'0';
next[k++]=i+'0';
}
else if(count[i]>=10)
{
next[k++]=count[i]/10+'0';
next[k++]=count[i]%10+'0';
next[k++]=i+'0';
}
else;
next[k]='\0';
}
int main()
{
while(1)
{
scanf("%s",n);
if(strcmp(n,"-1")==0)
break;
char temp[100];
strcpy(temp,n);
int k=15;
int t=0;
int found=0;
generate_next(n);
while(k--)
{
t++;
//cout<<next<<endl;
if(t==1&&strcmp(next,temp)==0)
{
printf("%s is self-inventorying\n",n);
found=1;
break;;
}
if(t>1&&strcmp(next,temp)==0)
{
printf("%s is self-inventorying after %d steps\n",n,t-1);
found=1;
break;
}
if(t>1&&strcmp(next,n)==0)
{
printf("%s enters an inventory loop of length %d\n",n,t);
found=1;
break;
}
strcpy(temp,next);
generate_next(temp);
}
if(!found)
printf("%s can not be classified after 15 iterations\n",n);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator