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 }
  • 相关阅读:
    互联网中的公钥与私钥
    Apache的order、allow、deny
    Linux进程中TIME_OUT解析
    no xxx find in java.library.path
    检测 USB 设备拨插的 C# 类库:USBClassLibrary
    C# 实现的异步 Socket 服务器
    javascript制作公式编辑器,函数编辑器和图形绘制
    浏览器内部工作原理
    10 款基于 jQuery 的切换效果插件推荐
    DIV焦点事件详解 --【focus和tabIndex】​
  • 原文地址:https://www.cnblogs.com/Annetree/p/7182221.html
Copyright © 2011-2022 走看看