当前位置:网站首页>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;
}
边栏推荐
- Idea create my first project
- 3.用数组逆序打印链表
- Codeforces Round #614 (Div. 2) B. JOE is on TV!
- 管道、管程、管态的区别
- 8、数组中出现次数超过一半的数字
- ACM寒假集训#7
- Install MySQL under centos7, and the online articles are not accurate
- [cloud based co creation] Huawei cloud: metastudio digital content production line, which seamlessly integrates the virtual world with the real world
- Ie compatibility problem handling
- PL/SQL server语法详解
猜你喜欢

SQL Server 2016 学习记录 --- 集合查询

多线程与高并发(三)—— 源码解析 AQS 原理

11. Linked list inversion

gcc: error trying to exec 'as': execvp: No such file or directory

Qt生成.exe文件 并 在无Qt环境下运行(Enigma Virtual Box进行绿色可执行软件封装)图文教程

Get to know SuperMap idesktop for the first time

SQL Server 2016 learning records - single table query

Typora使用教程

SQL Server 2016学习记录 --- 连接查询

ACM winter vacation training 5
随机推荐
试题 历届试题 发现环
SQL Server 2016 学习记录 --- 数据定义
IDEA打包jar包及运行jar包命令
逆元&组合数&快速幂
Inside story of Wu xiongang being dismissed by arm: did the establishment of a private investment company harm the interests of shareholders?
Sword finger offer
PL/SQL server语法详解
Uni app advanced life cycle
gcc: error trying to exec 'as': execvp: No such file or directory
2. Output one of the repeated numbers in the array
利用正则表达式从文件路径中匹配文件名
Idea packages jar packages and runs jar package commands
SQL Server 2016 learning records - connection query
ACM寒假集训#6
5. Dynamic programming -- Fibonacci series
集群为什么需要root权限
Why does the cluster need root permission
9. Delete nodes in the linked list
传全球半导体设备巨头或将于上海建合资工厂!
ACM winter vacation training 5