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

Re:Memory Limit Exceeded!!!!!!

Posted by DestinyDesigner at 2008-10-12 23:39:33 on Problem 2418
In Reply To:Memory Limit Exceeded!!!!!! Posted by:DestinyDesigner at 2008-10-12 23:38:50
> 为什么啊????
#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)
{
	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;
}

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