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> #include<cstring> #include<fstream> #include<algorithm> #include<string> #include<map> using namespace std; const int Max=200+10,inf=10000000; char a[Max]; int times; int process( char *sour) { int dig1[10]={0},dig2[10]={0}; int rank=0; map<string,int>m; string s; char t[Max],ch, a[Max]; strcpy(a,sour); s=a; m[s]=++rank; while(times<=15) { memset(dig1,0,sizeof(dig1)); times++; for(int i=0;a[i];i++) dig1[a[i]-'0']++; int tot=0; int len=0; for(int i=0;i<10;i++) { tot=dig1[i]; if(tot) { int t1=tot%10,t2=tot/10%10,t3=tot/100;// if(t3) { ch=t3+'0'; t[len++]=ch; ch=t2+'0'; t[len++]=ch; ch=t1+'0'; t[len++]=ch; } else if(t2) { ch=t2+'0'; t[len++]=ch; ch=t1+'0'; t[len++]=ch; } else if(t1) {ch=t1+'0'; t[len++]=ch; } ch=i+'0'; t[len++]=ch; } } t[len]='\0'; s=t; if(strcmp(sour,t)==0 && times==1) return 1; else if(m[s]!=0) { if( strcmp(a,t)==0) return 2; else { times=rank-m[s]+1; return 3; } } if(m[s]==0) m[s]=++rank; strcpy(a,t); //cout<<t<<endl; } return 4; } int main() { //freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); ifstream cin("in.txt"); while(cin>>a) { if(a[0]=='-')break; times=0; int ans=process( a ); if(ans==1) printf("%s is self-inventorying\n",a); else if(ans==2) printf("%s is self-inventorying after %d steps\n",a,times-1); else if(ans==3) printf("%s enters an inventory loop of length %d\n",a,times); else if(ans==4) printf("%s can not be classified after 15 iterations \n",a); } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator