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 |
不是过了么In Reply To:小弟的程序,请大家指教 Posted by:rickyjen at 2005-09-07 10:17:19 > #include "stdio.h" > #include "stdlib.h" > #include "string.h" > #define TIMES 17 //求inventory的次数 > #define LEN 165 //每个inventory的最大长度. > > void main() > { > void _free(struct str *&p); > void print(char *p,int n1,int n2); > void getinventory(char p[][LEN],int n); > char str[TIMES][LEN]; > int i,k,t; > while(1) > { > scanf("%s",str[0]); > if(str[0][0]=='-')break; > for(i=1;i<=16;i++) > { > getinventory(str,i);//求得string[i-1]的目录数字,存于string[i]中. > for(k=i-1;k>=0&&strcmp(str[i],str[k])!=0;k--); > if(k>=0)break; > } > if(i==17)i--; > print(str[0],i,k); > > } > } > void getinventory(char p[][LEN],int n)//求得p[i-1]的inventory,存于p[i]中. > { > void chang(char *p,int &pos,int n,char c); > int count,i,posi=0; > char c,*p1; > for(c='0';c<='9';c++) > { > for(p1=p[n-1],i=count=0;p1[i]!='\0';i++) > if(c==p1[i])count++; > chang(p[n],posi,count,c); > } > } > void chang(char *p,int &pos,int n,char c)//将整数n转化成字符'0','1'....存放pos开始的空间. > //然后将c也存入. > { > if(n) > { int w=1; > while(n%(w*10)!=n)w*=10; > for(;w>0;n%=w,w/=10)p[pos++]='0'+n/w; > p[pos++]=c; > p[pos]='\0'; > } > } > void print(char *p,int n1,int n2) > { > if(n1==1)printf("%s is self-inventorying\n",p); > else if(n2==n1-1)printf("%s is self-inventorying after %d steps\n",p,n2); > else if(n1==16)printf("%s can not be classified after 15 iterations\n",p); > else printf("%s enters an inventory loop of length %d\n",p,n1-n2); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator