当前位置:网站首页>20200229训练赛 L2 - 2 树种统计 (25分)
20200229训练赛 L2 - 2 树种统计 (25分)
2022-07-28 10:15:00 【小柳学渣】
随着卫星成像技术的应用,自然资源研究机构可以识别每一棵树的种类。请编写程序帮助研究人员统计每种树的数量,计算每种树占总数的百分比。
输入格式:
输入首先给出正整数N(≤10^5),随后N行,每行给出卫星观测到的一棵树的种类名称。种类名称由不超过30个英文字母和空格组成(大小写不区分)。
输出格式:
按字典序递增输出各种树的种类名称及其所占总数的百分比,其间以空格分隔,保留小数点后4位。
输入样例:
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
输出样例:
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键值对集合,键唯一不重复且有序(从小到大),有find()函数查找键,找不到则等于end()
找到:m.find(k)!=m.end()
找不到: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]++;//取值也可直接m[k];
}
for(auto i=m.begin();i!=m.end();i++)
{
//auto在c++11,需要配置dev,也可for(map<string,int>::iterator i=m.begin();i!=m.end();i++)
cout<<i->first<<" ";//i->first键
printf("%.4lf%%\n",i->second*1.0/n*100);//i->second值
}
return 0;
}
边栏推荐
- Uni app advanced life cycle
- ZTE: 5nm 5g base station chip is being introduced!
- Performance test of API gateway APIs IX in Google cloud T2a and T2D
- pt-kill 查询中包含中文字符 导致工具失效的排查
- Continue to write the greatest work based on modelarts [play with Huawei cloud]
- Sleeping barber problem
- SQL Server 2016 学习记录 --- 数据定义
- LIBCMTD.lib
- select如果不加order by子句,返回结果的顺序是不可靠的
- IE兼容性问题处理
猜你喜欢

SQL Server 2016 learning record - Data Definition

记录一次idea中的父子项目修改project与module名称,亲测!

第一篇:UniAPP的小程序跨端开发-----创建uniapp项目

SQL Server 2016 学习记录 --- 数据更新

15. Judge whether the target value exists in the two-dimensional array

Multithreading and high concurrency (III) -- source code analysis AQS principle
![Database security - create login user + configure permissions [notes]](/img/02/0c3eb542593e8e0a3a62db75c52850.png)
Database security - create login user + configure permissions [notes]

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

Typora使用教程

Voice chat app - how to standardize the development process?
随机推荐
14、双指针——盛最多水的容器
Kubernetes
PHP生成二维码(学习)
SuperMap iServer发布管理以及调用地图服务
pt-kill 查询中包含中文字符 导致工具失效的排查
[cloud co creation] enterprise digital transformation, Huawei cloud consulting is with you
Aqua Data Studio 18.5.0导出insert语句
Sleeping barber problem
Leetcode -- minimum number of rotation array
基于docker安装MySQL
6. Double pointer -- the sum of the two numbers of the incremental array is equal to the target number
[cloud based co creation] Huawei cloud: metastudio digital content production line, which seamlessly integrates the virtual world with the real world
It's settled! On July 30!
4.调整数组顺序使奇数位于偶数前面
JVM principle
SQL Server 2016学习记录 --- 单表查询
Get to know SuperMap idesktop for the first time
Performance test of API gateway APIs IX in Google cloud T2a and T2D
SQL Server 2016 learning records - data update
Lucene 查询语法备忘