POJ 2418 Hardwood species (binary sort tree)

Source: Internet
Author: User
Tags strcmp

Hardwood species
Time Limit: 10000MS
Memory Limit: 65536K
Total Submissions: 19428
Accepted: 7658

http://poj.org/problem?id=2418

Description

Hardwoods is the botanical group of trees that has broad leaves, produce a fruit or nut, and generally go dormant in the Winter.
America ' s temperate climates produce forests with hundreds of hardwood species--trees that share certain biological char Acteristics. Although oak, maple and cherry All is types of hardwood trees, for example, they is different species. Together, all the hardwood species represent-percent of the trees in the "states".

On the other hand, softwoods, or conifers, from the Latin word meaning "cone-bearing," has needles. Widely available US softwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. In a home, the softwoods is used primarily as structural lumber such as 2x4s and 2x6s, with some limited decorative appli Cations.

Using Satellite imaging technology, the Department of Natural Resources have compiled an inventory of every tree standing O n a particular day. You is to compute the total fraction of the tree population represented by each species.

Input

Input to your program consists of a list of the species of the every tree observed by the satellite, one tree per line. No species name exceeds-characters. There is no more than species and no more than 1,000,000 trees.

Output

Print The name of each species represented in the population, in alphabetical order, followed by the percentage of the Population it represents, to 4 decimal places.

Sample Input

Red Alderashaspenbasswoodashbeechyellow birchashcherrycottonwoodashcypressred Elmgumhackberrywhite Oakhickorypecanhard maplewhite oaksoft maplered oakred oakwhite oakpoplansassafrassycamoreblack WalnutWillow

Sample Output

Ash 13.7931Aspen 3.4483Basswood 3.4483Beech 3.4483Black Walnut 3.4483Cherry 3.4483Cottonwood 3.4483Cypress 3.4483Gum 3.4483Hackberry 3.4483Hard Maple 3.4483Hickory 3.4483Pecan 3.4483Poplan 3.4483Red Alder 3.4483Red Elm 3.4483Red Oak 6.8966 Sassafras 3.4483Soft Maple 3.4483Sycamore 3.4483White Oak 10.3448Willow 3.4483Yellow Birch 3.4483

Hint

This problem have huge input, use scanf instead of CIN to avoid time limit exceeded.

Source

Waterloo Local 2002.01.26 /*

With a binary sort of tree.

g++ WA;

C + + AC;

Data structure (Min) P228

*/


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace Std;
typedef char keytype;//type of keyword
typedef char elemtype;//type of insert element


typedef struct BITNODE
{
Keytype data[50];//node information for sorting binary tree
int count;
struct Bitnode *lchild;//left child pointer
struct Bitnode *rchild;//Right child pointer
}bitnode,*bitree;

int sum;


int EQ (Keytype a[],keytype b[])//judging a==b?
{
if (strcmp (A, b) ==0)
return 1;
Else
return 0;
}


int LT (Keytype a[],keytype b[])//judging a<b?
{
if (strcmp (A, b) <0)
return 1;
Else
return 0;
}


int Searchbst (bitree t,keytype key[],bitree f,bitree &p)
{
if (! T)//Find unsuccessful
{
p=f;
return 0;
}
Else if (EQ (key,t->data))//Find successful
       {
t->count++;
p=t;
return 1 ;
  }
Else if (LT (key,t->data))
return Searchbst (t->lchild,key,t,p);//continue to find in record
Else
return Searchbst (t->rchild,key,t,p);//Continue searching in the right subtree
}


void Insertbst (Bitree &t,elemtype e[])//insert operation
{
Bitree p;
if (! Searchbst (T,E,NULL,P))//insert operation when lookup is unsuccessful
{
Bitree s= (bitree) malloc (sizeof (Bitnode));//apply for dynamic storage space
s->lchild=s->rchild=null;
s->count=1;
strcpy (s->data,e);

if (!p)
T=s;
Else if (LT (e,p->data))
p->lchild=s;
Else
p->rchild=s;
}
}




void Inodertraverse (Bitree T)//middle sequence traversal sort binary tree
{
if (T)
{
Inodertraverse (t->lchild);
  printf ("%s%.4lf\n", T->data,100* ((t->count*1.0)/(sum*1.0)) );
Inodertraverse (t->rchild);
}

}




Char s[50];
void Createbst (Bitree &t)//create sort binary tree
{
while (gets (s) &&s[0]!= ')
{
Insertbst (t,s);
sum++;
}
}




int main ()
{
Bitree T=null;
Createbst (T);
Inodertraverse (T);
return 0;
}

POJ 2418 Hardwood species (binary sort tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.