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 ...
随机推荐
- <table>导出excal
<table>导出excal 将<table>导出为excal文件,这里介绍两种方法. 1.直接写代码,拼接出excal文件的字符串,然后直接用a标签下载.本人没有是试过,在此 ...
- nopi设置excel只读
- KMPlayer 一打开总是出现右面的窗口 导航区 怎样设置不会自动打开
两步骤第一,右键-外观-标致-管理 删除默认标致 第二,打开hosts文件,位置在 C:\Windows\System32\drivers\etc 在最下面一行加入 127.0.0.1 player. ...
- 浅谈JSONObject与JSONArray的区别
例如:一个json字符串如下: { "type":[{"a","1"},{"a","2"},{&qu ...
- dshow采集过程
捕捉静态图片常用的filter是Sample Graber filter,它的用法参考手册.然后将捕捉filter的静态PIN连接到Sample Grabber,再将Sample Grabber连接到 ...
- guava collection/cache初探
写了上面一篇,看了点eventbus相关的guava代码后,发现里面用到了很多其他guava包里的方法,所以顺着看一下,比如之前用到的map都是guava自己的 Multimap:可以包含有几个重复K ...
- linux查询硬件信息
硬件信息查询 sudo dmidecode -t baseboard
- Linux安装卸载jdk1.8
首先到官网下载 Linux x64 182.87 MB jdk-8u191-linux-x64.tar.gz https://www.oracle.com/technetwork/java/java ...
- Java IO流学习总结六:ByteArrayInputStream、ByteArrayOutputStream
类的继承关系 InputStream |__ ByteArrayInputStream OutputStream |__ ByteArrayOutputStream ByteArrayInputStr ...
- 第六次Scrum冲刺
第六次Scrum冲刺 1.成员今日完成情况 队员 今日完成任务 刘佳 前端构建 李佳 后端设计 周世元 数据设计 杨小妮 博客编写 许燕婷 管理团队当日及次日任务 陈水莲 性能测试用例设计 曾丽丽 性 ...