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

    package com.icil.elsa.subscribe.milestone.common.utils; import java.io.Serializable; import java.uti ...

  2. Redis 五大数据类型及常用操作

    # 更详细的操作命令请查看 => http://redisdoc.com/ 1: KEY ( 键值 )  => 常见操作 2: String ( 字符串 ), 最大支持 512M 2.1: ...

  3. CKEditor 5

    1.官网 https://ckeditor.com/ckeditor-5/download/ 2.

  4. Hadoop 基本原理

    Hadoop 有2大核心HDFS  (Hadoop Distributed File System)分布式文件系统  , MapRedurce 归约计算 HDFS  把文件按块存储, NameNode ...

  5. Haskell语言学习笔记(81)Data.Typeable

    Data.Typeable 利用 Data.Typeable,可以打印动态类型信息. class Typeable (a :: k) where typeRep# :: TypeRep a typeR ...

  6. python 问答

    1.list和tuple有什么区别? list是可变的,可以添加list.append,可以插入list.insert,可以改变元素值list[2] ='a':而tuple在初始化的时候就确定了,不能 ...

  7. 原生js上传文件,使用new FormData()

    当创建一个内容较多的表单,表单里面又有了文件上传,文件上传也需要表单提交,单一的上传文件很好操作: <form action="接口" enctype="multi ...

  8. Delphi 透明窗体显示文字

    设置窗体属性:BorderStyle 属性设置为 bsNoneColor 属性设置为 clWhite(白色:窗体背景色)TransparentColor 属性设置为 trueTransparentCo ...

  9. mybatis实现一对多连接查询

    问题:两个对象User和Score,它们之间的关系为一对多. 底层数据库为postgresql,ORM框架为mybatis. 关键代码如下: mybatis配置文件如下: mybatis.xml文件内 ...

  10. Structs复习 Action传递参数

    Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...