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啊,谁给个超过15步的数据让我测试一下,谢谢#include<iostream.h> #include<string.h> char*func(char*,int); int main() { char Num[16][81]; int i,count=0; while(1) { cin>>Num[0]; //cout<<Num[0]<<endl; if(Num[0][0]=='-') break; i=0; while(i<15) { count=0; strcpy(Num[i+1],func(Num[i],strlen(Num[i]))); if(strcmp(Num[i+1],Num[i])==0) { if(i==0) cout<<Num[0]<<" is self-inventorying "<<endl; else cout<<Num[0]<<" is self-inventorying after "<<i<<" steps "<<endl; //count=1; break; } if(strcmp(Num[i+1],Num[0])==0&&i>0) { cout<<Num[0]<<" enters an inventory loop of length "<<i+1<<endl; //count=1; break; } for(int j=0;j<=i;j++) { if(strcmp(Num[i+1],Num[j])==0) { cout<<Num[0]<<" enters an inventory loop of length "<<i+1-j<<endl; count=1; break; } } if(count==1) break; i++; } if(i>=15) cout<<Num[0]<<" can not be classified after 15 iterations "<<endl; } return 0; } char* func(char*a,int l) { int b[11]={0,0,0,0,0,0,0,0,0,0}; char c[21]; int k=0; for(int i=0;i<l;i++) { if(a[i]<='9'&&a[i]>='0') b[int(a[i]-'0')]++; } for(int j=0;j<10;j++) { if(b[j]!=0) { c[k]=b[j]+'0'; c[k+1]=j+'0'; k+=2; } } c[k]='\0'; return &c[0]; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator