强大的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. win7下文件名不能定义为con(任何文件格式)

    从linux传输压缩包到win7下解压缩,总是提示出错,可是在linux下解压都很正常,于是定位出错的文件,发现是con.c和con.h文件,经排查,原因如下: CON是DOS下的特殊设备名 如下由系 ...

  2. JAVA 线程学习 - Thread了解

    public class ThreadKnow { private TimeThread timeThread; private boolean flag; public ThreadKnow() { ...

  3. hive 0.10 0.11新增特性综述

    我们的hive版本升迁经历了0.7.1 -> 0.8.1 -> 0.9.0,并且线上shark所依赖的hive版本也停留在0.9.0上,在这些版本上有我们自己的bug fix patch和 ...

  4. Microsoft Deployment Toolkit 2013 Preview Release Now Available

    MDT 2013 provides a common console with comprehensive tools and guidance for every organizational ro ...

  5. HDU - 5009 Paint Pearls(dp+优化双向链表)

    Problem Description Lee has a string of n pearls. In the beginning, all the pearls have no color. He ...

  6. Objective-c 程序结构

    类是Objective-c的核心,Objective-c程序都是围绕类进行的.Objective-c程序至少包含以下三个部分: 1.类接口:定义了类的数据和方法,但是不包括方法的实现代码. 2.类实现 ...

  7. Javabean的理解

    1.Javabean是指满足指定规则的Java类.满足的规则由Sun公司提出,如x,setX,getX等规范,public无参构造函数等 2.Javabean其实也是一种规范.

  8. Objects

    Obeject Object Object representation and value representation Subobjects Polyomrphic objecets Alignm ...

  9. OD调试篇1—Hello

    OD调试篇1—Hello 要求:通过OD将程序的标题“I love fishc.com”改为“I love you” 一.找到程序的标题“I love fishc.com” 1.把程序拖到OD运行出现 ...

  10. [C#参考]事件和委托的关系

    前面说了委托,接下来就要说一说事件了,同时最后再说一下委托和事件的区别. 事件和委托很相似,事件就好像是被简化的针对特殊用途的委托.看下面的图: 从这张图中能看到,事件是发布者的一个成员,它不是类型. ...