ZOJ 2104 Let the Balloon Rise
2015-07-18 21:25
363 查看
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
简单题
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
简单题
#include<cstdio> #include<cstring> #include<iostream> #include<queue> #include<vector> #include<map> #include<cmath> #include<stack> #include<algorithm> #include<string> using namespace std; const int maxn = 1005; map<string, int> M; string s, S; int n, m; int main() { while (cin >> n, n) { m = 0; M.clear(); for (int i = 0; i < n; i++) { cin >> s; M[s]++; if (M[s]>m){ m = M[s]; S = s;} } cout << S << endl; } return 0; }
相关文章推荐
- poj3984-迷宫问题(广搜)
- Android学习笔记之dispatchTouchEvent和OnInterceptTouchEvent和OnTouchEvent三个方法之间的联系...
- Eddy's research I
- 【Spark Core】TaskScheduler源码与任务提交原理浅析1
- 每个程序员都需要了解的一个SQL技巧
- SWIFT中获取配置文件路径的方法
- 迭代器模式
- git使用的基础及常用命令
- ACdream 1727 Sequence
- 添加view类图中的二级菜单
- IntelliJ公司版破解方法
- LeetCode-Add and Search Word - Data structure design(C++)
- Java HashMap 的实现原理详解
- odoo联调补充
- 简单理解锁
- 1289 大鱼吃小鱼
- LeetCode: Rotate Array
- HDU 1233 还是畅通工程(Prim求最小生成树)
- 用这些专用工具让你截图更简单
- java中RowSet用法