HDU-1004.Let the ballon Rise(STL-map)
2019-02-28-08:56:03
初次做本题是用字符串硬钢,最近校队训练时又遇到才知道用map是真的舒服。需要注意的是map的用法。
clear :
清除map中的所有元素,map.clear();
erase:
删除 map 中指定位置的元素;map.erase(map.begin());
insert :
在 map 指定位置添加 pair 类型的元素;map.insert( pair< char, int >('f', 100) );
begin, end :
map 的正向迭代器的起始位置与终点位置;
rbegin, rend :
map 的反向迭代器的起始位置与终点位置;
map.first and map.second可访问map的第一个和第二个元素。
map中元素的插入方式:
方法一:pair
例:
map<int, string> mp;
mp.insert(pair<int,string>(1,"aaaaa"));
方法二:make_pair
例:
map<int, string> mp;
mp.insert(make_pair<int,string>(2,"bbbbb"));
方法三:value_type
例:
map<int, string> mp;
mp.insert(map<int, string>::value_type(3,"ccccc"));
方法四:数组
例:
map<int, string> mp;
mp[4] = "ddddd";
迭代器的申明方式:map<key_type, valye_type> :: iterator iter;
需要注意的是,如果申明map<string, int >类型的变量,如果你只是插入string,则其对应的value默认为0,并在之后遇到相同的key值是可对其value值进行自增操作。
#include <iostream>
#include <map>
using namespace std; map <string, int> ballon; int main () {
int n;
while(cin >> n && n) {
ballon.clear();
while(n --) {
string s;
cin >> s;
ballon[s] ++;
}
int max = ;
string maxcolor;
map<string, int > ::iterator iter;
for(iter = ballon.begin(); iter != ballon.end(); iter ++) {
if(iter -> second > max) {
max = (*iter).second;
maxcolor = (*iter).first;
}
}
cout << maxcolor << endl;
}
return ;
}
HDU-1004.Let the ballon Rise(STL-map)的更多相关文章
- HDU 1004 Let the Balloon Rise(map的使用)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- HDU 1004 - Let the Balloon Rise(map 用法样例)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdu 1004 Let the Balloon Rise(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- HDU 1004 Let the Balloon Rise【STL<map>】
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1004 Let the Balloon Rise(STL初体验之map)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDU 1004 Let the Balloon Rise map
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hdu 1004 Let the Balloon Rise strcmp、map、trie树
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1004 Let the Balloon Rise(map应用)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdu 1004 Let the Balloon Rise 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
随机推荐
- springMVC源码学习之addFlashAttribute源码分析
本文主要从falshMap初始化,存,取,消毁来进行源码分析,springmvc版本4.3.18.关于使用及验证请参考另一篇jsp取addFlashAttribute值深入理解即springMVC发r ...
- PE 装机
PE 装机 下载PE安装到硬盘启动. 下载win7安装原始文件ISO镜像文件,解压ISO到文件夹. 重启电脑,选择PE菜单. 打开windows安装器大全>选择 winntSetup> i ...
- 机器学习进阶-图像形态学变化-礼帽与黑帽 1.cv2.TOPHAT(礼帽-原始图片-开运算后图片) 2.cv2.BLACKHAT(黑帽 闭运算-原始图片)
1.op = cv2.TOPHAT 礼帽:原始图片-开运算后的图片 2. op=cv2.BLACKHAT 黑帽: 闭运算后的图片-原始图片 礼帽:表示的是原始图像-开运算(先腐蚀再膨胀)以后的图像 ...
- iOS多语言
https://blog.csdn.net/huangmindong/article/details/53464334 App多语言,字符串统一放在 Localizable.strings 文件里. ...
- javascript_ajax 地址三级联动
1.三级地址联动思路如下: 2.建立数据库.这里直接使用网上的地址数库,最后一个字段无用,先不去管它 3.建立一个server.php 文件 <?php // 数据库连接 mysql_conne ...
- c#与wpf的一些基础语法问题(摘用)
1 .在vs里不同cs文件,位于同一个namespace,是什么情况. 答:http://msdn.microsoft.com/zh-cn/library/0d941h9d(v=vs.80).aspx ...
- Zookeeper 在Linux系统的安装
注册中心Zookeeper 官方推荐使用 zookeeper 注册中心.注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者和消费者只在启动时与注册中心交互,注册中心不转发请求,压力较小. Z ...
- oracle第一天笔记
Oracle体系结构: 数据库 ----> 实例(orcl) ---> 表空间(逻辑单位)(用户) ---> 数据文件(物理单位) 地球 ----> 国家 ...
- 使用Node.JS监听文件夹变化
使用Node.JS监听文件夹改变有许多应用场合,比如: 构建自动编绎工具 当源文件改变时,自动运行build过程,比如当你写CoffeeScript文件或SASS CSS文件时,保存之后可即时生成对应 ...
- MySQL系统变量配置基础
本文出处:http://www.cnblogs.com/wy123/p/6595556.html MySQL变量的概念 个人认为可以理解成MySQL在启动或者运行过程中读取的一些参数问题,利用这些参数 ...