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)的更多相关文章

  1. 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 ...

  2. HDU 1004 - Let the Balloon Rise(map 用法样例)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. HDU 1004 Let the Balloon Rise(map应用)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. hdu 1004 Let the Balloon Rise 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...

  10. 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. 使用cuteFTP与虚拟机交互文件---安装ftp服务

    安装ftp服务,以便在Windows中使用cuteFTP与虚拟机交互文件,使用sudo apt-get install vsftpd 安装完后,打开/etc/vsftpd.conf文件,去掉local ...

  2. 机器学习进阶-图像形态学操作-膨胀操作 1.cv2.dilate(进行膨胀操作)

    1.cv2.dilate(src, kernel, iteration) 参数说明: src表示输入的图片, kernel表示方框的大小, iteration表示迭代的次数 膨胀操作原理:存在一个ke ...

  3. 机器学习入门-文本数据-构造Ngram词袋模型 1.CountVectorizer(ngram_range) 构建Ngram词袋模型

    函数说明: 1 CountVectorizer(ngram_range=(2, 2)) 进行字符串的前后组合,构造出新的词袋标签 参数说明:ngram_range=(2, 2) 表示选用2个词进行前后 ...

  4. Java ssl认证记录

    听到有人在用,所以自己随便搜了搜试了下,这里就是简单记录 就是操作了一遍这篇博文 https://blog.csdn.net/a495614205/article/details/12648939 i ...

  5. 【370】Python列表生成式(for 写入一行)

    参考: python用列表生成式写嵌套循环的方法_python_脚本之家 参考: python之列表生成式 - 旷野足迹 - 博客园 对于读取Twitter数据最终会得到一个超级复杂的json文件, ...

  6. 【原创】逆向练习(CrackMe)

    Write Up 登录的两个方法 方法1.用IDA分析 新版测试题.exe.在Strings Window中查找有一定意义的串. 从上面的窗口中,发现了CyberSwat和passwordisme这两 ...

  7. Angular2 web project UltraRacing (一,如何启动一个Angular项目?)

    要稍等一会 切到目录看看 OK,生成很多文件 那么 我们来启动吧 出现下面信息说明成功 而且每次我们编译文件后 都会在cmd里面显示这个信息 说明他是热部署的 然后我们去浏览器看看 说明一切OK!

  8. c++之enum(枚举)可以没有枚举名

    转载自https://blog.csdn.net/u013591613/article/details/71215000 C_enum(枚举)可以没有枚举名 如果声明枚举类型时没有指定枚举名,其作用就 ...

  9. 吴裕雄 oracle PL/SQL编程

  10. pandas.read_csv用法(转)

    的数据结构DataFrame,几乎可以对数据进行任何你想要的操作. 由于现实世界中数据源的格式非常多,pandas也支持了不同数据格式的导入方法,本文介绍pandas如何从csv文件中导入数据. 从上 ...