当前位置:网站首页>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;
}
边栏推荐
- ACM winter vacation training 4
- 管道、管程、管态的区别
- Inverse element & combinatorial number & fast power
- a different object with the same identifier value was already associated with the session
- Uni app project directory, file function introduction and development specification
- Typora使用教程
- SuperMap iserver publishing management and calling map services
- gcc: error trying to exec 'as': execvp: No such file or directory
- DBeaver的操作日志
- CentOS7下安装mysql5.7
猜你喜欢

Get to know SuperMap idesktop for the first time

PHP generates QR code (learning)

C语言 二级指针详解及示例代码

QT generation Exe file and run without QT environment (enigma virtual box for green executable software packaging) graphic tutorial

SQL Server 2016学习记录 --- 单表查询
![Database security - create login user + configure permissions [notes]](/img/02/0c3eb542593e8e0a3a62db75c52850.png)
Database security - create login user + configure permissions [notes]

Idea create my first project

ACM寒假集训#6

ACM寒假集训#5

Aqua Data Studio 18.5.0导出insert语句
随机推荐
16. String inversion
ACM winter vacation training 6
4. Adjust the array order so that odd numbers precede even numbers
20200217训练赛 L1 - 7 2019来了 (20分)
LIBCMTD.lib
Codeforces Round #614 (Div. 2) A. ConneR and the A.R.C. Markland-N
机器人技术(RoboCup 2D)实验五十题及主要函数含义
Shortest path topic
印度计划禁用中国电信设备!真离得开华为、中兴?
Go json.Decoder Considered Harmful
JVM principle
ACM winter vacation training 7
Install Office customization. Troubleshooting during installation
Database mysql Foundation
C语言 二级指针详解及示例代码
(1) Summary of machine learning concepts
2019年9月PAT甲级题目
Sword finger offer
机器学习--手写英文字母2--导入与处理数据
SDUT Round #9 2020-新春大作战