HDU 1004 MAP【STL__map_的应用】
强大的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_的应用】的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- HDU 1004 ballons(map)
题意:输出颜色最多的那个颜色. 思路:水题一道. #include <iostream> #include <string> #include <map> #inc ...
- HDU 1004 - Let the Balloon Rise(map 用法样例)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- hdu 1004 颜色与数字(map水题)
Sample Input5 //Tgreenredblueredred 统计颜色的次数 输出最多的颜色3pinkorangepink0 Sample Outputred pink # include ...
- HDU 1004 Let the Balloon Rise(map应用)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 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 ...
- 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 ...
随机推荐
- c语言各类问题 代码
定义一个结构体,有两个成员变量,一个整型的n,一个字符型的c,利用结构体类型声明一个具有5个元素的数组,并随机初始化,根据成员变量n进行从小到大排序,然后输出 冒泡排序然后 在输出结构体#includ ...
- linux cpu亲和性设置
1.设置进程的cpu亲和性程序如下, #Using:g++ setCpuAffinity.c -o setCpuAffinity #include<sys/types.h> #includ ...
- 电脑bios到底是什么?
没有哪个玩电脑的人不知道电脑bios,但是真正能明白bios是什么的?身边却没几个,甚至大多数电脑维修站的人员对bios也不够详细了解.一般人不去关心bios是因为它离我们的电脑真正使用仍有一段距离. ...
- 基于Visual C++2013拆解世界五百强面试题--题2-输出和为一个给定整数的所有组合
请用C语言实现 输出和为一个给定整数的所有组合 启动2012 /* 请用C语言实现 输出和为一个给定整数的所有组合 */ #include <stdio.h> //包含头文件stdio.h ...
- 提高IOS开发效率的常用网站、开源类库及工具
时间过得很快,学习iOS也已经2年左右了.在这里整理一下,在平台平常开发过程中使用比较多的开源类库.网站与工具吧! 一.网站: UI网站: 1.https://www.cocoacontrols.co ...
- HashMap和HashTable 学习
1. HashMap 1) hashmap的数据结构 Hashmap是一个数组和链表的结合体(在数据结构称“链表散列“),如下图示: 当我们往hashmap中put元素的时候,先根据key的hash ...
- [编程语言][java][java se]java泛型中? T K V E含义(学习)
? 表示不确定的java类型,类型是未知的. T 表示java类型. K V 分别代表java键值中的Key Value. E 代表Element,特性是枚举. 1.意思 jdk中的K,V, ...
- Three Swaps DFS
E. Three Swaps time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- asp.net中 服务器控件中onselectedindexchanged 没有反应的解决方案
最近发现项目中一个BUG就是 DropDownList 中的onselectedindexchanged 没有反应 AutoPostBack="true"和页面中的<%@ P ...
- .net平台是什么?.net平台的组成,.net平台的好处
1..net(dotnet)平台是什么? .net平台是微软公司设计的一个用于开发各种应用的"框架"和程序的运行环境. 2..net平台的组成: a..net Framework( ...