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 |
紧急求助 这道题MLE#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct tree { char s[35]; int count; struct tree*left; struct tree*right; }tree; typedef tree* tp; int n=0; void ins(tp *a,char*s) { tp tmp,tf; tmp=(tp)malloc(sizeof(tree)); strcpy(tmp->s,s); tmp->count=1; tmp->left=NULL; tmp->right=NULL; int use; tp from=*a,rp; if (!from) { *a=tmp; return; } while (from) { use=strcmp(from->s,s); if (!use) { from->count++; return; } rp=from; from=(use<0)?from->right:from->left; } if (use<0) rp->right=tmp; else rp->left=tmp; } void inordertraverse(tp head) { if (head) { inordertraverse(head->left); printf("%s %.4lf\n",head->s,head->count*100.0/n*1.0); inordertraverse(head->right); } } void del(tp head) { if (head) { del(head->left); del(head->right); free(head); } } int main() { int i; tp head=NULL; char str[35]; while (gets(str)) { n++; ins(&head,str); } inordertraverse(head); del(head); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator