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

本人小白,用map1485ms,自己写的BST1282ms~

Posted by 1196494730 at 2018-11-08 21:36:20 on Problem 2418
#include<iostream>
using namespace std;
struct BTree
{
	char value[35];
	int num;
	struct BTree *lchild;
	struct BTree *rchild;

};
void insert_node(BTree* &root,char *s1)
{
	if(root==NULL)
	{
		root=new BTree;
		strcpy(root->value,s1);
		root->lchild=NULL;
		root->rchild=NULL;
		root->num=1;
		return ;
	}
	if( strcmp(root->value,s1) ==0 )
	{
		root->num++;
		return ;
	}

	if(strcmp(root->value,s1)>0)
	{
		insert_node(root->lchild,s1);
	}
	else
		insert_node(root->rchild,s1);
}
void print(BTree *root,double total)
{
	if(root==NULL)
		return ;
	print(root->lchild,total);
	cout<<root->value<<" ";
	printf("%.4lf\n",(double)root->num/total *100);
	print(root->rchild,total);
}
int main()
{
	char s1[35];
	BTree * root=NULL;
	double total=0;
	while(gets(s1))
	{
		insert_node(root,s1);
		total++;
		//cout<<s1<<endl;
	}
	print(root,total);
	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