zoj 2104 Let the Balloon Rise(map映照容器的应用)
题目链接:
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映照容器的应用)的更多相关文章
- zoj 2104 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2 Seconds Memory Limit: 65536 KB Contest time again! How excit ...
- zoj 1109 Language of FatMouse(map映照容器的典型应用)
题目连接: acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 题目描述: We all know that FatMouse doe ...
- C++ map 映照容器
map映照容器的元素数据是一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系. map映照容器的数据结构是采用红黑树来实现的,插入键值的元素不允许重复,比较函数只对元素的键值进行比较, ...
- map映照容器的使用
map映照容器可以实现各种不同类型数据的对应关系,有着类似学号表的功能. 今天在做并查集的训练时,就用上了map映照容器. 题目就不上了,直接讲一下用法.顺便说一下,实现过程是在C++的条件下. #i ...
- map映照容器
//map映照容器是由一个键值和一个映照数据组成的,键值与映照数据之间具有一一映照的关系 //map映照容器的键值不允许重复 ,比较函数值对元素 //的键值进行比较,元素的各项数据可通过键值检索出来 ...
- 统计频率(map映照容器的使用)
问题描述 AOA非常喜欢阅读莎士比亚的诗,莎士比亚的诗中有种无形的魅力吸引着他!他认为莎士比亚的诗中之所以些的如此传神,应该是他的构词非常好!所以AOA想知道,在莎士比亚的书中,每个单词出现的频率各 ...
- POJ 1002 487-3279(map映照容器的使用)
Description Businesses like to have memorable telephone numbers. One way to make a telephone number ...
- map映照容器(常用的使用方法总结)
map映照容器的数据元素是由一个键值和一个映照数据组成的,键值和映照数据之间具有一一对应的关系.map与set集合容器一样,不允许插入的元素的键值重复. /*关于C++STL中map映照容器的学习,看 ...
- C++STL之map映照容器
map映照容器 map映照容器的元素数据是由一个键值和一个映照数据组成的, 键值与映照数据之间具有一一映照关系. map映照容器的数据结构也是采用红黑树来实现的, 插入元素的键值不允许重复, 比较函数 ...
随机推荐
- php支付宝手机网页支付类实例
<?php $alipayConfig = array( 'key' => 'xxxxx', //买卖安全校验码,用于签名的32位密钥 'transport' => 'https', ...
- Network in Network 2
<Network in Network>论文笔记 1.综述 这篇文章有两个很重要的观点: 1×1卷积的使用 文中提出使用mlpconv网络层替代传统的convolution层.mlp层实际 ...
- Sql Server Report 导出到EXCEL 指定行高
在SQL SERVER REPORT 2005做报表的时候,发现在report中指定的行高没有用.google了一下,找到了解决方法. Make both CanGrow and CanShrink ...
- WinForm中DataGridView的TextBoxColumm换行
一.内容超过显示宽度自动换行: 在需要自动换行的列中设置 二.换行符换行: 一开始在需要换行的文本添加"\r\n"并不能直接换行,DGV直接把\r\n显示出来了,后换成 Syste ...
- JQuery Mobile - 自定义图标!
环境 jquery1.9.1.js jquery mobile 1.4.2版 图标制作 18x18px 底透明的png图标 使用图标,这个过程开始怎么弄都不行,只有个灰色的圆出现,不见图标:或者出现图 ...
- 使用Samba实现文件共享
1987年,微软公司和英特尔公司,共同制定了SMB(Server Messages Block 服务消息块)协议,指在解决局域网内的文件或打印机等资源的共享问题,这也使得在多个主机之间共享文件变得越来 ...
- Mac下如何安装配置Homebrew
Last login: Mon Aug 7 13:57:29 on consolexiashenbindeMacBook-Pro:~ xiashenbin$ ruby -e "$(curl ...
- Shell - 简明Shell入门05 - 条件语句(Case)
示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var case $var in right) echo "Right!";; wrong) ...
- java批量读取多个文件并存入数据库
有时候服务运行的日志文件,需要统计分析,但数据量很大,并且直接在文件中看很不直观,这时可以将文件中的内容导入到数据库,入库后的数据就可以按照需求进行统计分析了. 这个是以服务器的访问日志作为示例,一个 ...
- POJ 2608
#include<iostream> #include<stdio.h> #include<string> #include<set> using na ...