当前位置:网站首页>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;
}
边栏推荐
- Etcd (highly available kV database)
- Xu Ziyang, President of ZTE: 5nm chip will be launched in 2021
- 7、二分法——寻找一组重复或者有序但是旋转的数组
- 【微信小程序】项目实战—抽签应用
- 剑指offer
- Database security - create login user + configure permissions [notes]
- 初识SuperMap iDesktop
- 利用正则表达式从文件路径中匹配文件名
- Detailed explanation of super complete knowledge points of instruction system
- Redis design specification
猜你喜欢

Typora使用教程

7. Dichotomy -- find a set of repeated or ordered but rotating arrays

PHP generates QR code (learning)

14、双指针——盛最多水的容器

用两个栈实现一个队列【C语言】

数据库安全 --- 创建登录名 用户+配置权限【笔记】
![[wechat applet] project practice - lottery application](/img/7b/a0545f077259b3dc971dc246813177.png)
[wechat applet] project practice - lottery application

SQL Server 2016学习记录 --- 单表查询

5. Dynamic programming -- Fibonacci series

多线程与高并发(三)—— 源码解析 AQS 原理
随机推荐
select如果不加order by子句,返回结果的顺序是不可靠的
数据库安全 --- 创建登录名 用户+配置权限【笔记】
jvm原理
Aqua Data Studio 18.5.0导出insert语句
Typora使用教程
Problem summary file
简介
IDEA创建我的第一个项目
Uni app advanced life cycle
India plans to ban China Telecom equipment! Can we really do without Huawei and ZTE?
Ueeditor v1.4.3 control file compression
指令系统超全知识点详解
发力大核、独显!英众科技2020十代酷睿独显产品发布
13、哈希表——两个链表第一个公共节点
Bitwise and, or, XOR and other operation methods
5. Dynamic programming -- Fibonacci series
Hurun released the 2020 top 10 Chinese chip design private enterprises: Huawei Hisilicon did not appear on the list!
DBeaver的操作日志
brief introduction
中芯国际科创板IPO顺利过会,市值有望突破2000亿!