当前位置:网站首页>20200229 training race L2 - 2 tree species Statistics (25 points)
20200229 training race L2 - 2 tree species Statistics (25 points)
2022-07-28 10:33:00 【Xiaoliu xuezha】
With the application of satellite imaging technology , The natural resources research institute can identify the type of each tree . Please write a program to help researchers count the number of each tree , Calculate the percentage of each tree in the total .
Input format :
The input first gives a positive integer N(≤10^5), And then N That's ok , Each line gives the species name of a tree observed by the satellite . The category name consists of no more than 30 English letters and spaces ( Case insensitive ).
Output format :
Incrementally output the category names of various trees and their percentage in the total number in dictionary order , Separated by spaces , After decimal point 4 position .
sample input :
29
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 Key value pair set , key The only one is not repeated and orderly ( From small to large ), Yes find() Function lookup key , If it cannot be found, it equals end()
find :m.find(k)!=m.end()
Can't find :m.find(k2)==m.end()
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
getchar();
map<string,int>m;
for(int i=0;i<n;i++)
{
string s;
getline(cin,s);
m[s]++;// The value can also be taken directly m[k];
}
for(auto i=m.begin();i!=m.end();i++)
{
//auto stay c++11, Need configuration dev, Can also be for(map<string,int>::iterator i=m.begin();i!=m.end();i++)
cout<<i->first<<" ";//i->first key
printf("%.4lf%%\n",i->second*1.0/n*100);//i->second value
}
return 0;
}
边栏推荐
- (1) Summary of machine learning concepts
- 2021-10-13arx
- 15. Judge whether the target value exists in the two-dimensional array
- Typora tutorial
- ACM winter vacation training 5
- Ie compatibility problem handling
- 14. Double pointer - the container that holds the most water
- Qt生成.exe文件 并 在无Qt环境下运行(Enigma Virtual Box进行绿色可执行软件封装)图文教程
- 13. Hash table - the first common node of two linked lists
- SQL Server 2016 learning records - connection query
猜你喜欢

IDEA打包jar包及运行jar包命令

14. Double pointer - the container that holds the most water

配置树莓派,过程和遇到问题

Record a parent-child project in idea, modify the name of project and module, and test it personally!

SQL Server 2016 learning records - single table query

C language secondary pointer explanation and example code

Excel word 简单 技巧 整理(持续更新 大概~)

SQL Server 2016 学习记录 --- 嵌套查询

Install Office customization. Troubleshooting during installation

7. Dichotomy -- find a set of repeated or ordered but rotating arrays
随机推荐
Use of Ogg parameter filter [urgent]
(1) Summary of machine learning concepts
Codeforces Round #614 (Div. 2) B. JOE is on TV!
Implement a queue with two stacks [C language]
最短路专题
10. The penultimate node in the linked list
漏洞分析丨HEVD-0x8.IntegerOverflow[win7x86]
Detailed explanation of super complete knowledge points of instruction system
SuperMap iserver publishing management and calling map services
gcc: error trying to exec 'as': execvp: No such file or directory
ACM寒假集训#7
SQL Server 2016学习记录 --- 单表查询
Chapter 1: cross end development of small programs of uniapp ----- create a uniapp project
LIBCMTD.lib
pt-kill 查询中包含中文字符 导致工具失效的排查
Small knowledge in Oracle
ACM寒假集训#4
Sword finger offer
2. Output one of the repeated numbers in the array
ACM winter vacation training 5