强大的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. [LeetCode]题解(python):069-Sqrt(x)

    题目来源: https://leetcode.com/problems/sqrtx/ 题意分析: 实现一个整型的开根. 题目思路: 利用牛顿迭代法可以求解.首先讲数据类型转成浮点数,然后选取初始值为n ...

  2. Storm几篇文章

    http://tianhailong.com/ http://www.cnblogs.com/panfeng412/archive/2012/07/02/storm-common-patterns-o ...

  3. C#使用系统的“显示桌面”功能(Shell.Application)

    原文 C#使用系统的“显示桌面”功能(Shell.Application) 在 Windows 系统的 任务栏 上的 快速启动栏 里,通常有一个图标  ,点击这个图标,就会切换到桌面.这个图标实际是一 ...

  4. 试用阿里云RDS的MySQL压缩存储引擎TokuDB

    以前就用过自己搭建MySQL服务器的两种存储引擎MyISAM和InnoDB(也用过一点Memory方式),在今年初转向阿里云关系型数据库服务RDS的时候,看到可调参数中有一个TokuDB,不过不太了解 ...

  5. Zookeeper 在Hadoop中的应用

    Zookeeper 简单介绍 Zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目.它主要是用来解决分布式应用中常常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集 ...

  6. OS之多线程

    os中引入进程的目的是,为了描述和实现多个程序的并发执行,以改善资源利用率及提高系统的吞吐量. 为什么要引入线程?这是为了减少程序并发执行时系统所付出的额外开销(堆栈切换的开销等),使os具有更好的并 ...

  7. 【转】利用Ajax.BeginForm提交文件

    Ajax.BeginForm @using (Ajax.BeginForm("YourAction", "YourController", new AjaxOp ...

  8. Java多线程之synchronized(一)

    在上节中已经说过了“非线程安全”是如何出现的,链接如下:http://www.cnblogs.com/chentong/p/5650137.html,那么怎么解决“非线程安全”问题呢,只需要在两个线程 ...

  9. TexturePacker 介绍

    TexturePacker这个词从字面来说就是Texture(纹理) + Packer(打包). 它是一款把若干资源图片拼接为一张大图的工具.它由一位叫做Andreas Loew的老外开发的 :). ...

  10. KMP算法的一个C++实现

    本文参考阮一峰老师的KMP算法,重点是“部分匹配表”的建立.算法可参考 http://kb.cnblogs.com/page/176818/ . /* * kmp.cpp * Author: Qian ...