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:原来是用于测试的代码没有去掉,呵呵In Reply To:我的是用树做的,为什么会wrong呢?牛人来帮我看一下 Posted by:songsong2008 at 2006-06-09 10:50:24 > #include <stdio.h> > char *a; > int duplicate=0; > typedef struct tree > { > int cnt; > char c; > struct tree * firstchild; > struct tree * nextsibling; > }Tree; > char convert(char c) > { > if(c>'P') > c--; > return (c-'A')/3+2+'0'; > } > void insert(char* number,int i,Tree * root) > { > //while(*number=='-') > //number++; > //if(strlen(number)==0) > //return 0; > Tree *p,*q; > if(i>=7) > return; > if(*number>'9' || *number<'0') > { > //printf("before convert %c\n",*number); > *number=convert(*number); > //printf("after convert %c\n",*number); > } > p=q=root->firstchild; > for(;(p!=NULL) && (p->c<*number);q=p,p=p->nextsibling); > //printf("%Tc",p->c); > if(root->firstchild==NULL || p==NULL || (p!=NULL&&p->c>*number)) > { > //printf("new%c",*number); > Tree * tmp=new Tree; > if(i==6) > tmp->cnt=1; > tmp->c=*number; > tmp->firstchild=NULL; > if(root->firstchild==NULL) > { > tmp->nextsibling=NULL; > root->firstchild=tmp; > } > else if(p==root->firstchild)//新来的作为firstchild,忘了这种情况 > { > tmp->nextsibling=p; > root->firstchild=tmp; > } > else > { > q->nextsibling=tmp; > tmp->nextsibling=p; > } > insert(++number,++i,tmp); > }//if NULl > else if(p->c==*number) > { > //printf("NotNew%c",p->c); > if(i==6) > { > p->cnt++; > return; > } > else > insert(++number,++i,p); > }//else !NULL > } > void travel(Tree * root,int i) > { > Tree *p; > if(i==7) > { > p=root; > //for(p=root->firstchild;p;p=p->nextsibling)//一个递归程序都写不好。。。。。 > //{ > if(p->cnt>=2) > { > duplicate=1; > //a[i]=p->c; > for(int j=0;j<7;j++) > { > if(j==3) > printf("-"); > printf("%c",a[j]); > }//for j > printf(" %d\n",p->cnt); > }//if > //}//for > } > else > { > for(p=root->firstchild;p;p=p->nextsibling) > { > a[i]=p->c; > travel(p,i+1); > } > } > } > void main() > { > int n; > char c; > char tmp[8]; > char * p=tmp; > Tree * root=new Tree; > root->firstchild=NULL; > root->nextsibling=NULL; > a=new char[7]; > scanf("%d\n",&n); > for(int i=0;i<n;i++) > { > for(int j=0;j<7;j++) > { > scanf("%c",&c); > if((c>='A'&&c<='Z') || (c>='0' && c<='9')) > tmp[j]=c; > else > j--; > }//for > tmp[7]='\0'; > printf("%s\n",tmp); > insert(p,0,root); > } > travel(root,0); > if(duplicate==0) > printf("No duplicates.\n"); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator