| ||||||||||
| 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 | |||||||||
好心人路过看哈……(数据我验证了下面列出的测试数据 都过了 为啥是compling error)#include <stdio.h>
#include <string.h>
#define n 81
char a[n];
char c[16][n];
void pd(char a[],int b[])
{
int k;
k=strlen(a);
for(int i=0;i<k;i++)
{
switch(a[i])
{
case '0':
b[0]++;
break;
case '1':
b[1]++;
break;
case '2':
b[2]++;
break;
case '3':
b[3]++;
break;
case '4':
b[4]++;
break;
case '5':
b[5]++;
break;
case '6':
b[6]++;
break;
case '7':
b[7]++;
break;
case '8':
b[8]++;
break;
case '9':
b[9]++;
break;
}
}
}
void main()
{
while(1)
{
scanf("%s",a);
if(strcmp(a,"-1")==0)
break;
strcpy(c[0],a);
int m;int x=0;
for(m=0;m<15;m++)
{
int b[10]={0};
pd(a,b);
strcpy(a,"\0");
for(int i=0;i<10;i++)
{
if(b[i]!=0)
{
char x[3];
if(b[i]>=10)
{
x[0]=b[i]/10+'0';
x[1]=b[i]%10+'0';
x[2]='\0';
}
else
{
x[0]=b[i]+'0';
x[1]='\0';
}
char y[2];
y[0]=i+'0';
y[1]='\0';
strcat(a,x);
strcat(a,y);
}
}
if(!strcmp(a,c[m]))
{
x=1;
if(m==0)
printf("%s is self-inventorying\n",c[0]);
else
printf("%s is self-inventorying after %d steps\n",c[0],m);
break;
}
strcpy(c[m+1],a);
}
if(!x)
{ int flag=0;
int t;
for(m=0;m<14;m++)
{
for(t=m+2;t<16;t++)
if(strcmp(c[m],c[t])==0)
{
printf("%s enters an inventory loop of length %d\n",c[0],t-m);
flag=1;
break;
}
if(flag)
break;
}
if(!flag)
printf("%s can not be classified after 15 iterations\n",c[0]);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator