| ||||||||||
| 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:Memory Limit Exceeded!!!!!!In Reply To:Re:Memory Limit Exceeded!!!!!! Posted by:DestinyDesigner at 2008-10-12 23:39:33 > #include "stdio.h"
> #include "stdlib.h"
> #include "string.h"
>
> typedef struct node
> {
> char name[31];
> int count;
> struct node *right,*left;
> }Node;
>
> Node *tmp;
> int total;
>
> void insert(Node *p)//改为以char name[]为参数。。
> {
> if(strcmp(tmp->name,p->name)==0) p->count++;
> else if(strcmp(tmp->name,p->name)<0)
> {
> if(p->left==NULL)
> {
> p->left=tmp;
> tmp->count++;
> }
> else insert(p->left);
> }
> else if(strcmp(tmp->name,p->name)>0)
> {
> if(p->right==NULL)
> {
> p->right=tmp;
> tmp->count++;
> }
> else insert(p->right);
> }
> }
>
> void walk(Node *p)
> {
> if(p!=NULL)
> {
> walk(p->left);
> printf("%s %.4f\n",p->name,p->count*100.0/total);
> walk(p->right);
> }
> }
>
> int main()
> {
> char s[31];
> int flag=1;
> total=0;
> Node *root=NULL;
> while(gets(s)!=NULL)
> {
> total++;
> tmp=(Node *)malloc(sizeof(Node));
> strcpy(tmp->name,s);
> tmp->count=0;
> tmp->left=tmp->right=NULL;
> if(flag)
> {
> root=tmp;
> flag=0;
> }
> insert(root);
> }
> walk(root);
> return 0;
> }
当发现一个新的品种的时候在创建一个NODE!!
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator