UVa 10226 - Hardwood Species

Summary
You are about to find out what is the percentage of each tree with respect to total number of trees.

Explanation
There is given the name of trees in any order. You have to find what is the percentage of appearence of unique trees in alphabetical order. Imaging the names of trees are:

aa xx aa

then, aa is 66.6667%, and xx is 33.3333%.

Gotchas

 * The character set is not defined in the question. Any character can be given. NOT only alphabetical letter and space.
 * Character from range [0,128] is enough for thinking.

Implementations

 * Code All the Problems

Optimizations
You can use Trie. It's quite good data structure for this problem.

struct node{ int cnt_trees; node *child[128]; node {       cnt_trees = 0; for(int i=0; i<128; i++) {           child[i] = NULL; }   } }*head;

Input
1

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

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