| ||||||||||
| 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 | |||||||||
2418题为什么我2008上能通过 ~~但是到这上面就compile error了~~大牛指点一下;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define Name_long 40
struct node
{
char name[Name_long];
int count;
struct node *left;
struct node *right;
}*root;
void Insert(struct node *root,char Tname[Name_long])
{
if(strcmp(root->name,"0")==0)
{
strcpy(root->name,Tname);
root->count=1;
root->left=NULL;
root->right=NULL;
}
else
{
if(strcmp(Tname,root->name)<0)
{
if(root->left==NULL)
{
if(!(root->left=(struct node *)malloc(sizeof(struct node))))
exit(-1);
strcpy(root->left->name,"0");
}
Insert(root->left,Tname);
}
else if(strcmp(Tname,root->name)>0)
{
if(root->right==NULL)
{
if(!(root->right=(struct node *)malloc(sizeof(struct node))))
exit(-1);
strcpy(root->right->name,"0");
}
Insert(root->right,Tname);
}
else if(strcmp(Tname,root->name)==0)
{
root->count++;
}
}
}
void InOrder(struct node *root,int num)
{
if(root!=NULL)
{
InOrder(root->left,num);
printf("%s %.4f\n",root->name,root->count*100.0/num);
InOrder(root->right,num);
}
}
void main()
{
char Tname[Name_long];
int num=0;
struct node *root=NULL;
if(!(root=(struct node *)malloc(sizeof(struct node))))
exit(-1);
strcpy(root->name,"0");
root->left=NULL;
root->right=NULL;
while(gets(Tname))
{
if(Tname[0]=='\0')
break;
Insert(root,Tname);
num++;
}
InOrder(root,num);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator