题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2104

题目描述:

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.

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.

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

5
green
red
blue
red
red
3
pink
orange
pink
0

Sample Output

red
pink

 /*问题 统计每种颜色气球的个数并输出
解题思路 问题本身很简单,使用结构体数组也可以做,这里提供一种map映照容器的做法,效率更高
具体做法:每读入一个字符串,先搜索该键值的是否存在,存在修改映照数据,不存在插入,最后遍历找到映照数据
最大即可*/
#include <cstdio>
#include <map>
#include <string>
using namespace std; int main()
{
int n;
char s[];
string colo;
map<string,int> m;
map<string,int>::iterator it,max;
while(scanf("%d",&n), n != )
{
while(n--)
{
scanf("%s",s);
colo=s;
it=m.find(colo);
if(it != m.end())
m[colo]++;
else
m[colo]=;
} max=m.begin();
for(it=m.begin(); it != m.end();it++){
if(it->second > max->second)
//if((*it).second > (*max).second)
max=it;
}
printf(max->first.c_str());//转换
putchar('\n');
m.clear();
}
return ;
}

zoj 2104 Let the Balloon Rise(map映照容器的应用)的更多相关文章

  1. zoj 2104 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2 Seconds      Memory Limit: 65536 KB Contest time again! How excit ...

  2. zoj 1109 Language of FatMouse(map映照容器的典型应用)

    题目连接: acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 题目描述: We all know that FatMouse doe ...

  3. C++ map 映照容器

    map映照容器的元素数据是一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系. map映照容器的数据结构是采用红黑树来实现的,插入键值的元素不允许重复,比较函数只对元素的键值进行比较, ...

  4. map映照容器的使用

    map映照容器可以实现各种不同类型数据的对应关系,有着类似学号表的功能. 今天在做并查集的训练时,就用上了map映照容器. 题目就不上了,直接讲一下用法.顺便说一下,实现过程是在C++的条件下. #i ...

  5. map映照容器

    //map映照容器是由一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系 //map映照容器的键值不允许重复 ,比较函数值对元素 //的键值进行比较,元素的各项数据可通过键值检索出来 ...

  6. 统计频率(map映照容器的使用)

    问题描述  AOA非常喜欢阅读莎士比亚的诗,莎士比亚的诗中有种无形的魅力吸引着他!他认为莎士比亚的诗中之所以些的如此传神,应该是他的构词非常好!所以AOA想知道,在莎士比亚的书中,每个单词出现的频率各 ...

  7. POJ 1002 487-3279(map映照容器的使用)

    Description Businesses like to have memorable telephone numbers. One way to make a telephone number ...

  8. map映照容器(常用的使用方法总结)

    map映照容器的数据元素是由一个键值和一个映照数据组成的,键值和映照数据之间具有一一对应的关系.map与set集合容器一样,不允许插入的元素的键值重复. /*关于C++STL中map映照容器的学习,看 ...

  9. C++STL之map映照容器

    map映照容器 map映照容器的元素数据是由一个键值和一个映照数据组成的, 键值与映照数据之间具有一一映照关系. map映照容器的数据结构也是采用红黑树来实现的, 插入元素的键值不允许重复, 比较函数 ...

随机推荐

  1. HTML 基础 块级元素与行内元素

    块元素:单独占一行,宽度占整行,可以包含内联元素和其他块元素,通过样式display:inline,变为行内元素,不换行 内联元素:不单独占一行,宽度根据内容来决定,只能容纳文本或者其他内联元素 ,可 ...

  2. 论EFMS模拟量部分采集电路的修改

    论1:电阻R11的作用 如图1是2014-3-11之前模拟量采集的部分硬件电路,图2是纠正后的正确电路. D5是SA20CA,TVS双向二极管,有效防止外接电源的浪涌冲击情况,保护电路.  D6是稳压 ...

  3. cxGrid实现取消过滤和排序后定位到首行(单选和多选)

    cxGrid实现取消过滤和排序后定位到首行(单选和多选) 原创 2013年10月06日 18:42:24 2107 DataContoller中的函数FocusedRecordIndex没有反应,Fo ...

  4. [ASE][Daily Scrum]11.05

    在昨天的课程之后经过讨论进行了初步的分工,并制定出了我们的一个两周计划. 尚没有和老师讨论,已经询问了时间没有收到回复,等老师那边讨论过后我会在更新这个部分. 第一阶段的目标是用户能够在一个空白的地图 ...

  5. ASP.NET MVC基础知识

    1.MVC项目文件夹说明 App_Data:用来保存数据文件,比如XML文件等: App_Start:包含mvc系统启动的相关类: Controller:存放整个项目“控制器”的代码文件: Model ...

  6. Speech Synthesis

    <Window x:Class="Synthesizer.MainWindow" xmlns="http://schemas.microsoft.com/winfx ...

  7. SO_REUSEADDR SO_REUSEPORT

    http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they ...

  8. java后端导入excel将数据写入数据库

    参考:https://www.cnblogs.com/hanfeihanfei/p/7079210.html @RequestMapping("/importExcel.do") ...

  9. js DOM 案例

    模态框 <html> <head> <meta charset="UTF-8"> <title>模态框</title> ...

  10. JavaScript(JS)简介

    历史背景介绍 (Brendan Eich)在其Netscape Navigator 2.0产品中开发出一套livescript的脚本语言.Sun和Netscape共同完成.后改名叫Javascript ...