Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

2418题为什么我2008上能通过 ~~但是到这上面就compile error了~~

Posted by zjjconan at 2010-10-24 19:55:36 and last updated at 2010-10-24 19:56:56
大牛指点一下;
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator