强大的MAP,今天终于开始好好学习一次。

map内部是用红黑树维持的有序结构。

定义:map<int,string>mapStudent;

查找的时间复杂度为对数级别.

1.构造方法学习两种:

第一种:用insert函数插入pair数据,mapStudent.insert(pair<int, string>(0,"jiangjing"));

第二种:用数组方式插入数据

mapStudent[1] = "jiangjing1";  mapStudent[2] =  "jiangjing2";

2.遍历也学习两种:

第一种:用迭代器遍历map<int, string>::iterator iter;

for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
cout<<iter->first<<" " <<iter->second<<endl;

第二种:用数组遍历

for(int nIndex = 0; nIndex < nSize; nIndex++)
cout<<mapStudent[nIndex]<<endl;

3.用count函数来判定关键字是否出现,出现返回1,没出现返回0;

用find函数来定位数据出现位置,它返回的一个迭代器,当数据出现时,它返回数据所在位置的迭代器,如果map中没有要查找的数据,它返回的迭代器等于end函数返回的迭代器,程序说明:

iter = mapStudent.find(1);

if(iter != mapStudent.end())
cout<<"Find, the value is "<<iter->second<<endl;
else
cout<<"Do not Find"<<endl;

source code:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std; const int INF = 0x3f3f3f3f; map <string, int> m;
string a, aa; int main(){
int i, j, t, n, numCase = ;
while(cin >> n){
if( == n) break;
m.clear();
for(i = ; i <= n; ++i){
cin >> a;
++m[a];
}
map <string, int> ::iterator it;
int Max = ;
for(it = m.begin(); it != m.end(); ++it){
if(it->second > Max){
Max = it->second;
aa = it->first;
}
}
cout << aa << endl;
}
return ;
}

HDU 1004 MAP【STL__map_的应用】的更多相关文章

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

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

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

  4. HDU 1004 ballons(map)

    题意:输出颜色最多的那个颜色. 思路:水题一道. #include <iostream> #include <string> #include <map> #inc ...

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

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

  6. hdu 1004 颜色与数字(map水题)

    Sample Input5 //Tgreenredblueredred 统计颜色的次数 输出最多的颜色3pinkorangepink0 Sample Outputred pink # include ...

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

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

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

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

随机推荐

  1. 微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回

    问题描述: php5.5已经把通过@加文件路径上传文件的方式给放入到Deprecated中了.php5.6默认是不支持这种方式了 解决办法curl处理 function curl_post($url, ...

  2. Python之登陆接口设计

    刚刚开始学习Python,第一个编写的程序. import os user_file = open('use_file.txt', 'r') user_list = user_file.readlin ...

  3. selenium + python自动化测试环境搭建--亲测

    环境准备: 1.下载所学安装包: setuptools https://pypi.python.org/packages/2.7/s/setuptools/ selenium https://pypi ...

  4. Qt socket中怎么传结构体?

    直接发送和接收结构体,例如:struct A {...};struct A objectA; 发送的时候: tcpSocket->write((char *)&objectA, size ...

  5. 基于Visual C++2013拆解世界五百强面试题--题17-程序结果分析1

    分析程序结果,分析过程我们就写在程序注释里面. 写出下列代码的输出内容 #include <stdio.h> int inc(int a) { return (++a); } int mu ...

  6. Android中获取系统的时间

    activity代码 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); set ...

  7. openstack之cinder

    一.cinder概述: 1.F版之前,并没有cinder,对应的组件为nova-volume:以Rest API的形式提供服务 2.cinder目标: 减少nova的复杂性,降低nova的负载,支持多 ...

  8. Extjs 3.0 htmleditor实现插入图片功能

    首先感谢前辈们的无私奉献.贴出参考地址 http://zhidao.baidu.com/link?url=Q0ZM405OFNy_xAHSut9TepRJxgXCxFayQttrQz1N82dlA1_ ...

  9. js得到分页栏

    自己写的,感觉返回html代码蠢蠢的,但是新手并不知道怎么写更好的,感觉这样子也蛮简单.记录下来,以后来越改越好. //获得分页栏.注意indexSize为奇数,这样也比较好看 //totalNum: ...

  10. 我在网站开发中经常用到的几个js函数01

    这是我在最近的一个网站项目中频繁用到的几个js函数,非常实用.包括:1.js获取地址栏参数:2.返回cookies字符串中指定键对应的值:3.json格式的日期转换为正常格式4.清除cookie. / ...