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 ...
随机推荐
- Miller_Rabin (米勒-拉宾) 素性测试
之前一直对于这个神奇的素性判定方法感到痴迷而又没有时间去了解.借着学习<信息安全数学基础>将素性这一判定方法学习一遍. 首先证明一下费马小定理. 若p为素数,且gcd(a, p)=1, 则 ...
- HDU 3389 (Nim博弈变形) Game
参考了众巨巨的博客,现在重新整理一下自己的思路. 首先在纸上画了一下转移图: 1 3 4号盒子是不能够再转移卡片到其他盒子中去了的,其他盒子中的卡片经过若干步的转移最终也一定会转移到1 3 4号盒子中 ...
- BZOJ3306: 树
3306: 树 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 311 Solved: 86[Submit][Status] Description ...
- 无线端通用的reset样式
@charset "utf-8"; html, body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, o ...
- web.xml整合s2sh内容
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...
- margin collapse 之父子关系的DIV
打算花点时间将知识整理一下,虽然平时现用现查都能完成工作,可是当遇到面试这种事情的时候,临时查就来不及了... 关于margin,整理若干知识点如下: 一:父子关系的DIV标签以及未加margin时的 ...
- js判断是否是pc
//判断是否是pc function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = new Array("An ...
- Java中sychronized方法与sychronized块区别
一.举几个栗子
- 收缩Oracle数据文件
最近有网友提到收缩Oracle数据文件的问题,这是DBA经常碰到的一个常见问题.通常我们需要收缩相应的数据文件以减少来自磁盘空间的压力以及提高数据库的整体性能.但这并非对于所有情形都是适用的,尤其是生 ...
- JBPM4之decision节点:1、好学生 | 坏学生
JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流程图的插件 JBPM4入门——3.JBPM4开发环境的搭建 JBPM4入门—— ...