Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 123800    Accepted Submission(s): 48826

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.

 
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
 
Author
WU, Jiazhi
 
Source
分析:STL大法好啊,本题要求最大的气球数,可以用到STL标准库中的map<string,int>来保存,当map的first插入一个string的时候,map的second++,就可以统计出具体的string的个数了,然后遍历找到最大值就可以了!
下面给出AC代码:
 #include <bits/stdc++.h>
using namespace std;
int main()
{
map<string,int>ballon;
int n;
string str;
while(cin>>n&&n)
{
ballon.clear();
while(n--)
{
cin>>str;
ballon[str]++;
}
int maxn=;
string maxcolor;
map<string,int>::iterator it;
for(it=ballon.begin();it!=ballon.end();it++)
{
if(it->second>maxn)
{
maxn=(*it).second;
maxcolor=(*it).first;
}
}
cout<<maxcolor<<endl;
}
return ;
}

HDU 1004 Let the Balloon Rise【STL<map>】的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdu 1004 Let the Balloon Rise(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

  4. 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 ...

  5. hdu 1004 Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. 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 ...

  7. hdu 1004 Let the Balloon Rise 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 用STL 中的 Map 写的 #include <iostream> #includ ...

  8. HDU 1004 - Let the Balloon Rise(map 用法样例)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. HDU 1004 Let the Balloon Rise(map应用)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. Sublime Text编辑器 + vim插件

    Sublime安装 Sublime Text 是一个代码编辑器.Sublime Text是由程序员Jon Skinner于2008年1月份所开发出来,它最初被设计为一个具有丰富扩展功能的Vim. Su ...

  2. 【Zookeeper】源码分析之服务器(一)

    一.前言 前面已经介绍了Zookeeper中Leader选举的具体流程,接着来学习Zookeeper中的各种服务器. 二.总体框架图 对于服务器,其框架图如下图所示 说明: ZooKeeperServ ...

  3. sublime学习笔记

    学习课程地址:快乐的sublime编辑器_sublime编辑器使用 另可参考笔记地址:http://c.haoduoshipin.com/happysublime/ PS:博主的一些文章地址:http ...

  4. bzoj 4310: 跳蚤

    Description 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究. 首先,他会把串分成不超过 k 个子串,然后对于每个子串 S,他会从S的所有子串中选择字典 ...

  5. JavaScript连等赋值

    最近探究js原理的过程中遇到了这个挺有趣的问题. 先贴代码: var a = {n:1} a.x = a = {n:2} alert(a.x) //undefined 在弄懂这个之前,我们先普及一个知 ...

  6. git 分支操作

    查看git分支: git fetch刷新git git branch  -a 列出所有的分支 git checkout origin/要切换的分支 git branch -r 查看远程分支 git c ...

  7. VS2017 调试期间无法获取到变量值查看

    只要把勾去掉就能查看变量的值了

  8. vue2 递归组件--树形

    递归组件,官方给的教程太简便了,根本看不出到底怎么用.于是自己查网摸索了一下,这儿只把核心思想写出来. 效果如下图,点击后打开二级菜单,再点击后打开三级. //js //引子//思想:当v-if='f ...

  9. Java异常的正确使用姿势

    最近在项目代码中,遇见异常滥用的情形,会带来什么样的后果呢? 1. 代码可读性变差,业务逻辑难以理解 异常流与业务状态流混在一起,无法从接口协议层面理解业务代码,只能深入到方法(Method)内部才能 ...

  10. javascript 之基本数据类型、引用数据类型区别--02

    栈(stack)和堆(heap) stack为自动分配的内存空间,它由系统自动释放:而heap则是动态分配的内存,大小不定也不会自动释放. 基本类型和引用类型 基本类型:存放在栈内存中的简单数据段,数 ...