当前位置:网站首页>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;
}
边栏推荐
- Detailed explanation of thread synchronization volatile and synchronized
- a different object with the same identifier value was already associated with the session
- ACM寒假集训#4
- QT generation Exe file and run without QT environment (enigma virtual box for green executable software packaging) graphic tutorial
- Chapter 1: cross end development of small programs of uniapp ----- create a uniapp project
- Lucene 查询语法备忘
- 试题 历届试题 发现环
- Ueeditor v1.4.3 control file compression
- SQL Server 2016 learning records - View
- Idea packages jar packages and runs jar package commands
猜你喜欢

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

C language secondary pointer explanation and example code

django-celery-redis异步发邮件

AP Autosar平台设计 1-2 导言、技术范围与方法

Shortest path topic

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

逆元&组合数&快速幂

Chapter 1: cross end development of small programs of uniapp ----- create a uniapp project

Install mysql5.7 under centos7

SuperMap iserver publishing management and calling map services
随机推荐
简介
gcc: error trying to exec 'as': execvp: No such file or directory
Sword finger offer
C语言 输入带空格的字符串
Context values traps and how to avoid or mitigate these traps in go
传全球半导体设备巨头或将于上海建合资工厂!
ACM winter vacation training 6
最短路专题
用两个栈实现一个队列【C语言】
Match file names from file paths using regular expressions
It is said that the global semiconductor equipment giant may build a joint venture factory in Shanghai!
Get to know SuperMap idesktop for the first time
Netease written test No. 2 -- typical application of European distance
gcc: error trying to exec 'as': execvp: No such file or directory
漏洞分析丨HEVD-0x8.IntegerOverflow[win7x86]
【栈的应用】--- 中缀表达式转后缀表达式
多线程与高并发(三)—— 源码解析 AQS 原理
[wechat applet] project practice - lottery application
中兴通讯总裁徐子阳:5nm芯片将在2021年推出
10. The penultimate node in the linked list