原题传送门:http://acm.hdu.edu.cn/statistic.php?pid=1004
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 73318 Accepted Submission(s): 27387
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.
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.
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
Recommend
Map 容器的使用:
#include<iostream> #include<map> #include<string> using namespace std; int n,maxNum; string a; string maxColor; map<string,int> ballon; int main() { while(cin>>n) { if(!n)break; maxNum = 0; ballon.clear(); for(int i=0;i<n;i++){ cin>>a; ballon[a]++; } map<string,int>::iterator ite; for(ite = ballon.begin();ite!=ballon.end();ite++){ if(ite->second >maxNum){ maxNum = ite->second; maxColor = ite->first; } } cout<<maxColor<<endl; } return 0; }
相关推荐
« ACM模板收集Let the Balloon Rise » Catalan数 Catalan numbers 的公式: Cn=C(2n,n)/(n+1);1 Cn+1=C(2n+2,n+1)/(n+2);2 由1和2推出 Cn/C(n+1)=(n+2)/(4n+2); 而且,对于一个具有n个节点的数的形态的...
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
For a positive integer n, let’s denote function f(n,m) as the m-th smallest integer x that x>n and gcd(x,n)=1. For example, f(5,1)=6 and f(5,5)=11. You are given the value of m and (f(n,m)?n)⊕n,...
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU最全ac代码
自己做的HDU ACM已经AC的题目
hdu动态规划算法集锦
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. Input Input...
hdu题目分类