zoukankan      html  css  js  c++  java
  • HDU 1004 Let the Balloon Rise(map应用)

    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
     
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #include<vector>
     5 #include<cstring>
     6 #include<string>
     7 #include<algorithm>
     8 #include<map>
     9 using namespace std;
    10 
    11 
    12 int main()
    13 {
    14     int n;
    15     while(~scanf("%d",&n)&&n)
    16     {
    17         map<string,int>m;//声明容器
    18         map<string,int>::iterator it;//声明迭代器
    19         string color;
    20         for(int i=0;i<n;i++)
    21         {
    22             cin>>color;
    23             m[color]++;
    24         }
    25         int max=0;
    26         string ans;
    27         for(it=m.begin();it!=m.end();it++)
    28         {
    29             if(it->second>max)
    30             {
    31                 max=it->second;
    32                 ans=it->first;
    33             }
    34         }
    35         cout<<ans<<endl;
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    Python for i 循环
    Python 输入分数并评
    用户名和密码的输入
    cocos2d-x 3.0学习
    VS2008 ShotKey
    Cocos2d-x 3.0的安装方法
    VFC
    一、在WIN7 64位系统平台,VS2013环境下安装WTL90_4090_RC1(2014-04-01)
    http://www.vcf-online.org/
    Win7 64位 VS2012 安装 Qt5
  • 原文地址:https://www.cnblogs.com/Annetree/p/7182221.html
Copyright © 2011-2022 走看看