HD1004Let the Balloon Rise
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58555 Accepted Submission(s): 21498
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
用map,简单易懂
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
int n;
while(cin>>n,n){
map<string, int> counters;
string s;
while(n--){
cin >> s ;
++counters[s];
}
map<string, int>::const_iterator it = counters.begin(),j = counters.begin();
for (;it != counters.end(); ++it) {
if(it->second > j->second)
j = it;
}
cout<<j->first<<endl;
}
return ;
}
在讨论区里看到有人用了clear(),不知效率会不会高一些,大神鉴定一下,代码大概是这样(ac了的)
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
int n;
map<string, int> counters;
string s; while(cin>>n,n){
int max = ;
while(n--){
cin >> s ;
++counters[s];
if(counters[s] > max)
max = counters[s];
}
map<string, int>::const_iterator it = counters.begin();
for (;it != counters.end(); ++it) {
if(it->second == max)
cout<<it->first<<endl;
}
counters.clear();
}
return ;
}
HD1004Let the Balloon Rise的更多相关文章
- hdu 1004 Let the Balloon Rise
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Let the Balloon Rise 分类: HDU 2015-06-19 19:11 7人阅读 评论(0) 收藏
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
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- akoj-1073- Let the Balloon Rise
Let the Balloon Rise Time Limit:1000MS Memory Limit:65536K Total Submit:92 Accepted:58 Description ...
- 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 ...
- Let the Balloon Rise(水)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...
- ACM Let the Balloon Rise
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...
随机推荐
- phpStorm连接mysql
小结:牛逼的IDE
- 推荐 10 款最好的 Python IDE
简述 Python 非常易学,强大的编程语言.Python 包括高效高级的数据结构,提供简单且高效的面向对象编程. Python 的学习过程少不了 IDE 或者代码编辑器,或者集成的开发编辑器(IDE ...
- Quickhit快速击键
一.项目分析 根据输入速率和正确率将玩家分为不同等级,级别越高,一次显示的字符数越多,玩家正确输入一次的得分也越高.如果玩家在规定时间内完成规定次数的输入,正确率达到规定要求,则玩家升级.玩家最高级别 ...
- UVa 1395 Slim Span【最小生成树】
题意:给出n个节点的图,求最大边减最小边尽量小的值的生成树 首先将边排序,然后枚举边的区间,判定在该区间内是否n个点连通,如果已经连通了,则构成一颗生成树, 则此时的苗条度是这个区间内最小的(和kru ...
- 02.C语言关于指针的学习笔记
指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址. 要搞清一个指针需要搞清指针的四方面的内容: 指针的类型,指针所指向的 类型,指针的值或者叫指针所指向的内存区,还有指针本身所占据的内 ...
- singleton单例模式
单例设计模式 单例设计模式概述 单例模式就是要确保类在内存中只有一个对象,该实例必须自动创建,并且对外提供 优点: 在系统内存中只存在一个对象,因此可以解决系统资源,对于一些需要频繁 ...
- == Rickard Oberg & TheServerSide
看了Hani Suleiman和Rickard Oberg ,发现其实每个所谓的权威都应该有被质疑的绝对,可能往往权威会令人觉得理所应当
- JVM——判断对象的死活
一.引用计数法 给对象中添加一个引用计数器,每当有一个地方引用它时,计数器值就加1,当引用失效时,计数器值就减1,任何时刻计数器为0的对象就是不可能再被使用的. 但是它很难解决对象之间相互循环引用的问 ...
- hadoop-初学者写map-reduce程序中容易出现的问题 3
1.写hadoop的map-reduce程序之前所必须知道的基础知识: 1)hadoop map-reduce的自带的数据类型: Hadoop提供了如下内容的数据类型,这些数据类型都实现了Writab ...
- oracle 导入数据时提示只有 DBA 才能导入由其他 DBA 导出的文件
提示: IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件 IMP-00000: 未成功终止导入 解决方法: 用户system用户登录然后授权 grant dba to hszx