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 ...
随机推荐
- 机器学习进阶-案例实战-答题卡识别判 1.cv2.getPerspectiveTransform(获得投射变化后的H矩阵) 2.cv2.warpPerspective(H获得变化后的图像) 3.cv2.approxPolyDP(近似轮廓) 4.cv2.threshold(二值变化) 7.cv2.countNonezeros(非零像素点个数)6.cv2.bitwise_and(与判断)
1.H = cv2.getPerspectiveTransform(rect, transform_axes) 获得投射变化后的H矩阵 参数说明:rect表示原始的位置左上,右上,右下,左下, tra ...
- python 阿狸的进阶之路(7)
面向对象 转自林海峰的博客 http://www.cnblogs.com/linhaifeng/articles/6182264.html 面向对象的理解: 将数据分类,比如学生类.数据有关的函数, ...
- bash中 2>&1 & 的解释
1.首先,bash中0,1,2三个数字分别代表STDIN_FILENO.STDOUT_FILENO.STDERR_FILENO,即标准输入(一般是键盘),标准输出(一般是显示屏,准确的说是用户终端控制 ...
- vim主题设定
Vim的颜色主题在/usr/share/vim/vim74/colors文件夹里. 打开vim后在normal模式下输入“:colorscheme”查看当前的主题,修改主题使用命令“:colorsch ...
- vue中嵌套页面(iframe)
vue中嵌套iframe,将要嵌套的文件放在static下面.(要将打包文件整体放在statici里,我的文件名是canvas) src可以使用相对路径,也可使用服务器根路径http:localhos ...
- Python读取图片尺寸、图片格式
Python读取图片尺寸.图片格式 需要用到PIL模块,使用pip安装Pillow.Pillow是从PIL fork过来的Python 图片库. from PIL import Image im = ...
- MS SQL大值数据类型varchar(max)、nvarchar(max)、varbinary(max)
在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max).nvarchar(max).varbinary(max) ).大值数据类型最多可以存储2^30-1个字节的数据. 这几 ...
- set 转 enumeration
- netty 集成 wss 安全链接
netty集成ssl完整参考指南(含完整源码) 虽然我们在内部rpc通信中使用的是基于认证和报文头加密的方式实现安全性,但是有些时候仍然需要使用SSL加密,可能是因为对接的三方系统需要,也可能是由于o ...
- 获取url后面的参数的方法
1. function GetRequest() { var url = 'http://wwww.jb51.net/?q=js'; //获取url中"?"符后的字串 if (ur ...