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 ...
 
随机推荐
- [ 记录 ] Vue 对象数组中一项数据改变,页面不更新
			
问题描述:将data中数据列表渲染到页面,循环生成 el-switch,点击页面中 el-switch 后数组中某项值改变,但是页面不更新 数据格式如下 export default{ data(){ ...
 - php实现单点登录,顶级域名与子域名间共享Cookie实现单点登录原理
			
这是一个简单版的php单点登录概述,如果需要实现复杂的需自己,编写复杂的ticket加解密算法. 先看张图. sso系统,http://sso.yxh.com 1 2 3 4 5 <?php ...
 - idea 与springboot 快捷键
			
ctrl + m 还原 查询 getmapping 修改默认端口号
 - APP-2-Hbuilder开发环境搭建
			
1.Hbuilder下载 http://www.dcloud.io/hbuilderx.html 2.夜神模拟器下载 https://www.yeshen.com/ 3.chrome浏览器下载 htt ...
 - Java如何判断当前系统是Windows 还是LInux
 - 页面ajax自带的访问后台时,正在加载中
			
ajax自带访问后台时,提示正在加载中,加载完成后自动消除遮罩层,代码如下: var mask=mui.createMask();//遮罩层 //传统ajax的post请求方式 mui.ajax('h ...
 - Zookeeper 基本应用及盲点
			
主要应用 From: https://segmentfault.com/a/1190000012185452 http://blog.fens.me/zookeeper-queue/ 原理: 应用zo ...
 - 飞利浦 PHILIPS 电动牙刷HX6730 拆解
			
今日,一直比较喜欢用的电动牙刷,飞利浦HX6730坏掉了,初步感觉考虑飞利浦的保修,但是发现发票找不到了.飞利浦的客服也说,电动牙刷的两年保修依据分别是:1.发票开据日期:2.在无发票的情况下,看底部 ...
 - Zabbix监控Zookeeper健康状况
			
首先最简单的是监听服务端口,在zabbix界面直接添加监控项 item: zookeeper.status key: net.tcp.listen[2181] ZooKeeper监控要点: 内 ...
 - Android内存优化相关
			
Android的内存管理方式 Android系统内存分配与回收方式 一个APP通常就是一个进程对应一个虚拟机 GC只在Heap剩余空间不够时才去垃圾回收 GC触发时,所有线程都会被暂停!!! APP内 ...