c++中的map
来源:互联网 发布:js获取回调函数返回值 编辑:程序博客网 时间:2024/06/01 18:54
c++提供的map容器,头文件#include<map>,map的特点是存储的都是键值对,键具有唯一性。键值对之间是一一对应的关系。如:map<string,int> color;那么键的类型是string,值是int.color[red]=1;
相当于一种特殊的数组,数据排序不用是int 。
Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.
This year, they decide to leave this lovely job to you.
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.
A test case with N = 0 terminates the input and this test case is not to be processed.
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
Sample Input
5greenredblueredred3pinkorangepink0
Sample Output
redpink
#include<iostream>#include<stdio.h>#include<map>#include<string>using namespace std;int main(){int N;int max;string str;string index;map<string,int>color;while(scanf("%d",&N),N){max=0;for(int i=0;i<N;i++){cin>>str;color[str]++;if(color[str]>max){index=str;max=color[str];}}cout<<index<<endl;}return 0;}
阅读全文
1 0
- c++stl中的map/multimap
- C++STL:移除map中的元素
- 关于Oracle 12c 中的Heat Map
- 【C++】:C++ STL中的map 详解
- c++map
- c++MAP
- map(c++)
- c++map
- C++map
- 关于C语言中的Map(thinkvd 开发日志)
- C++STL中的set容器和map容器
- c++primer关联容器中的“单词转换map程序”分析
- 使用<c:forEach>标签遍历List中的map元素
- 【c/c++】map
- Map.Entry和Map中的map.keySet()、map.entrySet()详解
- Map java中的map 如何修改Map中的对应元素
- javascript中的map
- JAVA中的Map
- 使用Matplotlib创建散点图
- gitlab系统的安装和使用教程
- 人脸识别之遍历ORL人脸文件
- 欢迎使用CSDN-markdown编辑器
- HDOJ--2152Fruit!!母函数
- c++中的map
- JavaScript.Node对象属性
- 如何抽取代码后,在父类实例化泛型的问题
- java基础(个人版)
- 二维码
- DFS全排列
- 关于自动驾驶L1~L5的等级划分,这次认真聊一聊
- 神经网络算法
- Tp3.2和Tp5.0之间的区别