博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Let the Balloon Rise
阅读量:2242 次
发布时间:2019-05-09

本文共 1749 字,大约阅读时间需要 5 分钟。

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 
Total Submission(s): 123205 Accepted Submission(s): 48540

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 

green 
red 
blue 
red 
red 

pink 
orange 
pink 
0

Sample Output 
red 
pink

解题思路:用map就很美滋滋,给map中插入时如果不成功,返回已有的节点给他加加,即给second(value)++

#include  #include 
#include
using namespace std; int main() {
int num; while(scanf("%d",&num) == 1 && num){
map
mp; int cnt = 0; string color; for (int i = 0; i < num; ++i) {
string s; cin>>s; mp[s]++; } map
::iterator it = mp.begin(); for (; it != mp.end(); ++it) {
if (cnt < it->second) {
cnt = it->second; color= it->first; } } cout<
<

转载地址:http://ltgbb.baihongyu.com/

你可能感兴趣的文章
泛型与通配符详解
查看>>
BaseServiceImpl中的实现关键点
查看>>
Struts2中的session、request、respsonse获取方法
查看>>
如何理解MVC模型
查看>>
SpringMVC中乱码解决方案
查看>>
SpringMVC中时间格式转换的解决方案
查看>>
post和get请求相关知识点
查看>>
关于try finally 中的return语句的问题
查看>>
RequestBody/ResponseBody处理Json数据
查看>>
springmvc请求参数获取的几种方法
查看>>
在eclipse中创建和myeclipse一样的包结构
查看>>
Java中的IO流
查看>>
java中的关键字
查看>>
如果某个方法是静态的,它的行为就不具有多态性
查看>>
优化Hibernate所鼓励的7大措施
查看>>
Java 8系列之重新认识HashMap
查看>>
HashMap 、 ArrayList、String 重写了equals方法 而Object类(比如User)没有重写
查看>>
Servlet的生命周期
查看>>
Object中的getClass()返回的是当前运行的类
查看>>
加载驱动程序的方法
查看>>