Hardwood Species
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 18770   Accepted: 7405

Description

Hardwoods are the botanical group of trees that have 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 characteristics. Although oak, maple and cherry all are types of hardwood trees, for example, they are different species. Together, all the
hardwood species represent 40 percent of the trees in the United States. 



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



Using satellite imaging technology, the Department of Natural Resources has compiled an inventory of every tree standing on a particular day. You are 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 every tree observed by the satellite; one tree per line. No species name exceeds 30 characters. There are no more than 10,000 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 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
题意:给一堆单词(有反复),然后按字典序打印出全部单词(无反复) 而且输出每一个单词占总单词数的百分率。
值得注意的是G++提交要用%f 而C++用%lf
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string x;
long long cnt=0;
map <string,int> m;
while(getline(cin,x)){
cnt++;
m[x]++; }
map <string,int>::iterator it=m.begin();
while(it!=m.end())
{
printf("%s ",it->first.c_str());
printf("%.4lf\n",it->second*100.0/cnt);
++it;
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

POJ 2418-Hardwood Species(map)的更多相关文章

  1. POJ - 2418 Hardwood Species(map,trie,BST)

    1.输入若干行树名,输入结束后,按字典序输出树名及其所占百分比. 2.多种方法:map,trie,BST 3. map: #include<iostream> #include<st ...

  2. Hardwood Species(map)

    http://poj.org/problem?id=2418 题意:给定一系列字符串,要求按字典序升序输出每个串,并输出每个串出现的百分比. 用map做的,交c++A了,G++ WA..so sad. ...

  3. [字典树] poj 2418 Hardwood Species

    题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS   Memory ...

  4. POJ 2418 Hardwood Species(STL在map应用)

    职务地址:id=2418">POJ 2418 通过这个题查了大量资料..知道了非常多曾经不知道的东西. . .. 在代码中凝视说明吧. 代码例如以下: #include <ios ...

  5. [ACM] POJ 2418 Hardwood Species (Trie树或map)

    Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 713 ...

  6. POJ 2418 Hardwood Species

                                                     Hardwood Species Time Limit: 10000MS   Memory Limit ...

  7. Hardwood Species(水)

    Time Limit:10000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u SubmitStatus Descrip ...

  8. poj 2418 Hardwood Species (map)

    题目:http://poj.org/problem?id=2418 在poj 上交题总是有各种错误,再次感叹各个编译器. c++ AC代码,G++为超时,上代码: #include<cstdio ...

  9. POJ 2418 Hardwood Species (哈希,%f 和 %lf)

    我的错因: 本来改用%f输出,我用了%lf,结果编译器直接判定为错误(一部分编译器认为lf是没有错的).当时我还以为是hash出错了.. 方法不止一种: 方法 时间   空间 Hash 891ms 5 ...

随机推荐

  1. UVA 294 294 - Divisors (数论)

    UVA 294 - Divisors 题目链接 题意:求一个区间内,因子最多的数字. 思路:因为区间保证最多1W个数字,因子能够遍历区间.然后利用事先筛出的素数求出质因子,之后因子个数为全部(质因子的 ...

  2. Android 一个异步SocketHelper

    发送流程:首先定义一个缓冲池,发送数据时仅仅是将待发送的数据加入到缓冲池中,再由后台的工作线程从缓冲池中取得待发送数据进行发送.可能某些情况下在数据发送完成时需要做一些处理(比如写日志),便定义了一个 ...

  3. AJAX有关的请求协议及HTTP报文

    URI:统一资源标识符 URI=URL+URNURL:统一资源定位符URN:统一资源名称 上边的图片编号对应下边的编号说明: 1.HTTP(占90%市场)/HTTPS/FTP 传输协议(可以理解为快递 ...

  4. Java Lock Example – ReentrantLock(java锁的例子)

    Welcome to Java Lock example tutorial. Usually when working with multi-threaded environment, we use ...

  5. 【Struts2三】拦截器

    拦截器:就是在訪问action之前.对其进行拦截!能够在拦截器中做一些逻辑的处理! 比方权限验证.没有权限就不给予訪问! 拦截器等效于servlet中的过滤器! 使用拦截器步骤: 1.定义自己的拦截器 ...

  6. js进阶 12-13 jquery中one方法和trigger方法如何使用

    js进阶 12-13 jquery中one方法和trigger方法如何使用 一.总结 一句话总结: 1.one()方法和on()方法的区别是什么? 除了one()只执行一次,其它和on()一模一样,包 ...

  7. Mac怎么设置wifi热点

    苹果 Mac 系统中要把无线当作 Wifi 热点来用的话,需要电脑有其它网络接入才可以,也就是说它需要一个可以用于上网的网络,比如有线网络.尤其是对于使用 MacBook Pro 或 MacBook ...

  8. eclipse在线安装超级炫酷黑色主题

    Darkest Dark Theme插件: 点击菜单栏 Help --> Eclipse Marketplace,输出Darkest Dark Theme进行搜索,如下图: 本主题有17套编辑器 ...

  9. ZOJ 3336 Friend Number II

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3780 题目大意: 给你一个正整数x,要求每个数字上的总和和x相同且比x大的最小 ...

  10. SetForegroundWindow

    SetForegroundWindow 函数功能:该函数将创建指定窗口的线程设置到前台,并且激活该窗口.键盘输入转向该窗口,并为用户改各种可视的记号.系统给创建前台窗口的线程分配的权限稍高于其他线程. ...