[ACMcoder] Let the Balloon Rise

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

解题思路

实现代码

#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
    int n;
    string color;
    while (cin>>n)
    {
        if (n == 0) break;
        unordered_map<string, int> colormap;
        while (n--)
        {
            cin>>color;
            colormap[color]++;
        }

        int max = 0;
        int count;
        string popColor;
        for (auto it = colormap.begin(); it != colormap.end(); it++)
        {
            count = it->second;
            if (count > max)
            {
                max = count;
                popColor = it->first;
            }
        }
        cout<<popColor.c_str()<<endl;
    }
}
时间: 2024-07-30 07:13:20

[ACMcoder] Let the Balloon Rise的相关文章

HDOJ 1004题 Let the Balloon Rise strcmp()函数

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

HDOJ 1004 Let the Balloon Rise

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

vb的属性、方法和事件(一)

Visual Basic的窗体和控件是具有自己的属性.方法和事件的对象.可以把属性看作一个对象的性质,把方法看作对象的动作,把事件看作对象的响应.日常生活中的对象,如小孩玩的气球同样具有属性.方法和事件.气球的属性包括可以看到的一些性质,如它的直径和颜色.其它一些属性描述气球的状态(充气的或未充气的)或不可见的性质,如它的寿命.通过定义,所有气球都具有这些属性:这些属性也会因气球的不同而不同. 气球还具有本身所固有的方法和动作.如:充气方法(用氦气充满气球的动作),放气方法(排出气球中的气体)和

HDOJ1001-1005题解

1001--Sum Problem(http://acm.hdu.edu.cn/showproblem.php?pid=1001) #include <stdio.h> int sum(int n) { if(n % 2) return (n + 1) / 2 * n; else return (n / 2) * (n + 1); } int main() { int n; while(scanf("%d",&n) != EOF){ printf("%d\

蚂蚁金服合作的RISE实验室到底有多牛?

近日,蚂蚁金服与美国加州伯克利大学近期新成立的RISE实验室达成合作意向.RISE实验室的前身是著名伯克利AMP实验室,主导研发了当今大数据计算领域最前沿的开源系统:Apache Spark.Apache Mesos.以及 Alluxio (又名"Tachyon").以Apache Spark为例,作为大数据处理的计算引擎,它具备 DAG 执行引擎以及基于内存的多轮迭代计算等优势,使得其在数据分析等工作负载上表现优秀,成为大数据领域最活跃的开源项目之一.  此前,蚂蚁金服和清华大学.同

毁了你的童年 《Balloon Party》评测

毁了你的童年!! 游戏名称:Balloon party 上架时间:2012年7月24日游戏价格:免费游戏大小:25.9MB这些天小编都在关注一款名为<Balloon Party>的小游戏,虽然并没有如小编预想的那样登上app store的榜单,但是却在小编心里的好游戏排行榜中占位很高.这样一款休闲.趣味的同时也能锻炼大脑的游戏很适合脑细胞急需上升的小编.游戏截图各式各样的气球画面设计可爱

蚂蚁金服与UC Berkeley RISE实验室启动合作,加速数据人才培养

近日,蚂蚁金服向雷锋网(公众号:雷锋网)透露与美国加州伯克利大学近期新成立的RISE实验室达成合作意向.据悉,本次蚂蚁金服和RISE实验室的合作,是对海内外数据技术人才引进的布局.蚂蚁金服董事长彭蕾曾在内部讲话中表明蚂蚁金服对大数据技术的人才引进将"不拘一格,不遗余力". RISE实验室的前身是著名伯克利AMP实验室,主导研发了当今大数据计算领域最前沿的开源系统:Apache Spark和Apache Mesos.以Apache Spark为例,作为大数据分析处理的计算引擎,它具备 D

Infographic: The Rise and Rise of the Ubiquitous Cloud

From its humble, text-based beginnings less than three decades ago, the Web has quickly grown into an all-encompassing behemoth that in­fluences every aspect of our daily lives. Now, as the internet and cloud begin to seamlessly merge together, a new

[ACMcoder] Sum Problem

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + - + n. Input The input will consist of a series of integers n, one integer per line. Output For each ca