| ||||||||||
| 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 | |||||||||
为什么WA?#include <iostream>
using namespace std;
long i,now,flag,n,nows,x,y;
long a[10];
char str[101][101];
int main ()
{
while (1)
{
cin>>str[0];
if (str[0][0]=='-') break;
flag=0;
now=0;
while (1)
{
if (flag!=0) break;
for (i=0;i<=9;i++)
a[i]=0;
for (i=0;i<strlen(str[now]);i++)
a[(long)(str[now][i])-48]++;
nows=0;
for (i=0;i<=9;i++)
if (a[i]>0) {
if (a[i]<=9) {
str[now+1][nows]=(char)(a[i]+48);
str[now+1][nows+1]=(char)(i+48);
nows=nows+2;
}
if ((a[i]>9)&&(a[i]<=99)) {
str[now+1][nows]=(char)((a[i]/10)+48);
str[now+1][nows+1]=(char)((a[i]%10)+48);
str[now+1][nows+2]=(char)(i+48);
nows=nows+3;
}
if (a[i]>99) {
str[now+1][nows]=(char)((a[i]/100)+48);
str[now+1][nows+1]=(char)(((a[i]/10)%10)+48);
str[now+1][nows+2]=(char)((a[i]%10)+48);
str[now+1][nows+3]=(char)(i+48);
nows=nows+4;
}
}
str[now+1][nows]='\0';
for (i=0;i<now+1;i++)
if (strcmp(str[i],str[now+1])==0) {
x=i;
y=now+1;
flag=1;
break;
}
if ((now==15)&&(flag==0)) flag=2;
now++;
}
if (flag==2) {
cout<<str[0]<<" can not be classified after 15 iterations"<<endl;
continue;
}
if ((x==0)&&(y==1)) cout<<str[0]<<" is self-inventorying"<<endl;
else {
if (x==y-1) {
cout<<str[0]<<" is self-inventorying after "<<x<<" steps"<<endl;
}
else {
cout<<str[0]<<" enters an inventory loop of length "<<y-x<<endl;
}
}
}
return (0);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator