map 树木品种

树木品种

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 517   Accepted: 120  

Description

硬木是一种宽叶林木,生产水果或坚果,而且在冬天冬眠。

美国的温带气候生产出数百种的硬木森林,也就是有着某些共同的生物学特性的树木群。虽然橡木,枫木,樱桃都是硬木树种类型,但是,它们是不同的物种。总之,所有的硬木树种占据了美国百分之四十的树木。

另一方面,软木或针叶树(针叶来自拉丁词,意思是“锥轴承”)它们的叶子呈针状,在美国广泛使用的软木包括雪松,冷杉,铁杉,松,红杉,云杉和桧。在家里,软木主要用于结构性木材,如2x4s和2x6s,和一些装饰。

利用卫星成像技术,自然资源部记录一天中每一颗树的目录。你要计算出每个品种树木的数量。

Input

输入中包括一列由卫星观察到的每天各颗树的品种,每棵树一行。品种名称少于30个字符。品种数目不超过10,000 树木总数不超过1,000,000.

Output

按字母顺序输出树木的品种,然后是这种品种在整体中占的比例,精确到四位小数。

Sample Input

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

Sample 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

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceeded.

 1 #include <iostream>
 2 #include <string>
 3 #include <map>
 4 #include <cstdio>
 5 using namespace std;
 6 int main() {
 7     map<string, int> mapp1;
 8     string s;
 9     int count = 0; 
10     while(getline(cin, s)){
11         mapp1[s]++;
12         count++;
13     }
14     cout.setf(ios::fixed);
15     cout.precision(4);
16     for(map<string, int>::iterator it = mapp1.begin(); it != mapp1.end(); it++){
17         double per = 100 * ((double)it->second / (double)count);
18         cout << it->first << " " << per << endl;
19     } 
20     return 0;
21 }
View Code
原文地址:https://www.cnblogs.com/qinduanyinghua/p/5506710.html