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 |
RE了很久啊,很费解,求高手指点一番#include<stdio.h> #include<string.h> #include<stdlib.h> char str[82],str1[16][82],str3[82],str4[82],str5[82]; int fu[82],fu1[82]; char *func1(char st[]) { int lenth,i,j,k,l; int c; memset(str3,0,sizeof(str3)); memset(fu,0,sizeof(fu)); memset(fu1,0,sizeof(fu1)); lenth=strlen(st); for(j=0;j<lenth;j++) { for (i=0;i<lenth-j-1;i++) if (st[i]>st[i+1]) { c=st[i]; st[i]=st[i+1]; st[i+1]=c; } } for(i=0;i<lenth;i++) { fu[i]=st[i]-48; } i=0; l=0; while(i<lenth) { c=fu[i]; j=0; for(k=i;k<lenth;k++) { if(fu[k]==c) j++; else break; } i+=j; fu1[l++]=j; fu1[l++]=c; } fu1[l]=-1; for(i=0;fu1[i]!=-1;i++) { if(fu1[i]>=10) { for(j=l;j>=i;j--) { fu1[j+1]=fu1[j]; } c=fu1[i]; fu1[i]=c/10; fu1[i+1]=c%10; } } for(i=0;fu1[i]!=-1;i++) { str3[i]=fu1[i]+48; } str3[i]='\0'; return str3; } int main() { int i,flag,j; scanf("%s",str); getchar(); sscanf(str,"%s",str5); while(strcmp(str,"-1")) { memset(str1,0,sizeof(str1)); flag=0; sscanf(func1(str),"%s",str1[0]); for(i=1;i<15;i++) { memset(str4,0,sizeof(str4)); strcpy(str4,str1[i-1]); sscanf(func1(str4),"%s",str1[i]); } for(i=0;i<15;i++) { if(strcmp(str5,str1[i])==0) { if(i==0) { printf("%s is self-inventorying\n",str5); flag=1; break; } else { printf("%s enters an inventory loop of length %d\n",str5,i+1); flag=1; break; } } } if(flag==0) { for(i=0;i<15;i++) { if(flag!=0) break; for(j=i+1;j<15;j++) { if((strcmp(str1[i],str1[j])==0)&&(j-i)==1) { printf("%s is self-inventorying after %d steps\n",str5,i+1); flag=1; break; } if(strcmp(str1[i],str1[j])==0) { printf("%s enters an inventory loop of length %d\n",str5,j-i); flag=1; break; } } } } if(flag==0) { printf("%s can not be classified after 15 iterations\n",str5); } memset(str,0,sizeof(str)); memset(str5,0,sizeof(str5)); scanf("%s",str); strcpy(str5,str); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator