Ecology
Time limit1sMemory limit256 MB
Count how many times each tree species line appears, then print each species in lexicographic order with its share of the total, rounded to four decimals.
Problem
In ecology, measuring the distribution of trees is important. Given a list of trees found across the United States, write a program that computes what percentage of all the trees each species accounts for.
Input
The input consists of several lines, with one tree species name per line. No species name is longer than 30 characters. There are at most 10,000 distinct species and at most 1,000,000 trees. A species name may contain spaces, so treat each entire line as a single species name.
Output
Print the name of every species that appears in the input in alphabetical (lexicographic) order. After each name, print the percentage of the total number of trees that the species represents, rounded to four decimal places. The percentage is computed as (number of trees of that species) × 100 ÷ (total number of trees), and the name and value are separated by a single space.
Hint
The input may contain only uppercase and lowercase English letters, space characters, digits, and special characters.