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 |
汗,交的时候忘了注释掉"gets(str);"了,多输入了In Reply To:郁闷,不知道哪错了....二叉排序树做的,哪位大牛帮忙看看啊! Posted by:ecjtuxsyuan at 2007-12-20 19:34:45 > //PKU 2418 郁闷,不知道哪错了...... > > #include<stdio.h> > #include<string.h> > #include<ctype.h> > #include<stdlib.h> > typedef struct BSTNode > { > char treeName[100]; > int times; > struct BSTNode *lchild,*rchild; > }BSTNode,*BSTree; > int count; > void InsertBST(BSTree &t,char name[]) > { > BSTree p,f; > p=t; > while(p) > { > if(strcmp(p->treeName,name)==0) > { > p->times++; > return ; > } > f=p; > p=(strcmp(name,p->treeName)<0)?p->lchild:p->rchild; > } > p=(BSTree)malloc(sizeof(BSTNode)); > strcpy(p->treeName,name); > p->lchild=p->rchild=NULL; > p->times=1; > if(t==NULL)t=p; > else > { > if(strcmp(p->treeName,f->treeName)<0) > f->lchild=p; > else f->rchild=p; > } > } > void InOrderTraverse(BSTree &t) > { > if(t!=NULL) > { > InOrderTraverse(t->lchild); > printf("%s %.4f\n",t->treeName,t->times*100.0/count); > InOrderTraverse(t->rchild); > } > } > int main() > { > char str[100]; > BSTree t = NULL; > count=0; > //int z=29; > while(gets(str)) > //while((z--)>0) > { > gets(str); > InsertBST(t,str); > count++; > } > InOrderTraverse(t); > //scanf("%d",&count); > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator