Hardwood Species

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

题目大意:

    给定一堆字符串,输出每个字符串出现的概率。

解题思路:

    水题。用map<string,int>来存放每个字符串出现的次数。

    注意:输出按字典序排序。

Code:

  1. /*************************************************************************
  2. > File Name: poj2418.cpp
  3. > Author: Enumz
  4. > Mail: 369372123@qq.com
  5. > Created Time: 2014年10月26日 星期日 21时14分37秒
  6. ************************************************************************/
  7.  
  8. #include<iostream>
  9. #include<cstdio>
  10. #include<cstdlib>
  11. #include<string>
  12. #include<cstring>
  13. #include<list>
  14. #include<queue>
  15. #include<stack>
  16. #include<map>
  17. #include<set>
  18. #include<algorithm>
  19. #include<cmath>
  20. #define MAXN 100000
  21. using namespace std;
  22. map <string,int> m;
  23. string Trie[MAXN];
  24. int main()
  25. {
  26. int i=;
  27. string tmp;
  28. int k=;
  29. int sum=;
  30. while (getline(cin,tmp))
  31. {
  32. sum++;
  33. m[tmp]++;
  34. if (m[tmp]==)
  35. Trie[k++]=tmp;
  36. }
  37. sort(Trie+,Trie+k);
  38. for (int i=;i<k;i++)
  39. {
  40. cout<<Trie[i]<<" ";
  41. double ret=(double)m[Trie[i]]*/(double)sum;
  42. printf("%.4lf\n",ret);
  43. }
  44. return ;
  45. }

POJ2418——Hardwood Species(map映射)的更多相关文章

  1. POJ2418 Hardwood Species—二叉查找树应用

    1. Hardwood Species原题描述   Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 14326   Acce ...

  2. poj 2418 Hardwood Species (map)

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

  3. POJ-2418 Hardwood Species(二叉搜索树)

    思路就是先将每个单词存进二叉树中,没出现一次,修改该单词所在结点的cnt++: 最后通过递归中序遍历输出结果. 思路很清晰,主要注意一下指针的使用,想一想为什么要这么用? 简单的解释就是,insert ...

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

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

  5. 洛谷 UVA10226 Hardwood Species

    洛谷 UVA10226 Hardwood Species 洛谷评测传送门 题目描述 PDF 输入格式 输出格式 输入输出样例 输入 #1复制 输出 #1复制 题目翻译: 给定若干字符串,输出格式为:( ...

  6. POJ 2418 Hardwood Species

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

  7. Hardwood Species 分类: POJ 树 2015-08-05 16:24 2人阅读 评论(0) 收藏

    Hardwood Species Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 20619 Accepted: 8083 De ...

  8. Hardwood Species(水)

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

  9. POJ 2418 ,ZOJ 1899 Hardwood Species - from lanshui_Yang

    Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nu ...

随机推荐

  1. 输入整数n(n<=10000),表示接下来将会输入n个实数,将这n个实数存入数组a中。请定义一个数组拷贝函数将数组a中的n个数拷贝到数组b中。

    代码一大串! #include<stdio.h> ],y[]; void arraycopy (double c[],double d[],int m); { ;i<=m;i++) ...

  2. AspectJ的简单使用

    aspectj是一款优秀的面向切面的编程框架,下面就简单介绍一下入门教程吧: 1.官网下载AspectJ的jar包,我这里下的是最新版本1.8.7的. 2.因为AspectJ.jar 是一个可执行的j ...

  3. zabbix短信网关调用问题总结

    在写调用短信网关的shell脚本的时候,发现了一个百思不得其解的问题,用浏览器访问短信接口地址是可以成功接收到短信的.但在shell 里面调用就报错了!!!在反复测试当中发现,在shell 中对特殊字 ...

  4. DB Cache Reloaded Fix缓存不能被激活解决方法

    1.创建wp-content/plugins/db-cache-reloaded-fix/cache目录. 2.将cache权限改为777. 3.拷贝wp-content/plugins/db-cac ...

  5. 《编写高质量代码-Web前端开发修改之道》笔记--第二章 团队合作

    本章内容: 揭秘前端开发工程师 欲精一行,必先通十行 增加代码的可读性--注释 提高重用性--公共组件和私有组件的维护 冗余和精简的矛盾--选择集中还是选择分散 磨刀不误砍柴工--前期的构思很重要 制 ...

  6. 非常出色的一款WinForm窗体重绘GUI类库源码

    基本控件的演示 ScrollBar滚动条 各种圆形进度条 ProgressBar进度条 Mdi演示,仿谷歌浏览器 多种皮肤可供选择 一套专业级别的GUI控件,目前包含了窗体.进度条.滚动条以及MDI多 ...

  7. Redis的PHP操作手册

    String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...

  8. php中类的声明与使用

    <?php /**php语言是支持面向对象编程的,对于面向对象的编程,学过java和C++的人都知道啊! *如果不清楚的去baidu问一下就可以了. */ //我们来定义一个类,定义类的关键字是 ...

  9. Linux下通过shell脚本创建账户

    当我们在linux平台上开发一些项目时,或者有一些项目是需要部署到linux系统上时,有时候会涉及到linux上的特定的账户,例如有一些项目需要运行在某些特定的账户下,或者有时候需要在全新的环境上搭建 ...

  10. ajax中的post方法中回调函数不执行的问题

    前一段时间接触了JQuery Ajax中的.post()方法和.get()方法,感觉到ajax的简洁和强大,当用到.post()方法时,去W3上查找相关的使用方法,感觉十分简单,用法很明了,然后,直接 ...