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 ...
随机推荐
- html_表单
一.表单框架简介 表单是提供让读者在网页上输入,勾选和选取数据,以便提交给服务器数据库的工具.(用于将信息提交给服务器) <form>...</form>标记 作用:用于创建一 ...
- Linux进程控制(三)
1. 进程间打开文件的继承 1.1. 用fork继承打开的文件 fork以后的子进程自动继承了父进程的打开的文件,继承以后,父进程关闭打开的文件不会对子进程造成影响. 示例: #include < ...
- bzoj4518
好久没写题解了…… 一开始脑抽,还以为平均数会随着划分的改变而改变(无可救药……) 这题还是比较水的,展开方差的式子分成m部分每部分路程为xi,平均数p 方差=∑(xi-p)/m=∑(xi^2-2xi ...
- core--进程
前面我们说了线程是一系列的指令,那么进程是什么呢?进程就是装下这些指令的容器.该容器除了线程,还包含资源等内容.一个进程至少要有一个线程.没有线程的进程就不叫进程 "进程和程序的区别:进程必 ...
- UVa 11624 (BFS) Fire!
也是一个走迷宫的问题,不过又有了点变化. 这里迷宫里有若干把火,而且火每秒也是向四个方向蔓延的.问人是否能走出迷宫. 我用了两遍BFS,第一遍把所有着火的格子加入队列,然后计算每个格子着火的时间. 第 ...
- yii2.0 事务
$transaction=\Yii::$app->db->beginTransaction(); $model=Customer::findOne(1); $model->name= ...
- Python time mktime()方法
描述 Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数. 如果输入的值不 ...
- 关于Xcode的项目文件夹
当我们在打开的项目中,对某个文件夹 Show in Finder的时候,发现对代码的分类文件夹没有全在一堆,在项目中明明对代码分了类,为什么在Finder中没有文件夹?? 这是因为,Xcode项目中的 ...
- 获取Request请求的路径信息
从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...
- 14、NFC技术:使用Android Beam技术传输文本
Android Beam的基本理念 Android Beam的基本理念就是两部(只能是两部)NFC设备靠近时(一般是背靠背),通过触摸一部NFC设备的屏幕,将数据推向另外一部NFC设备.在传递数据的过 ...