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 }
  • 相关阅读:
    VUE的生命周期
    ID生成算法(二)
    ID生成算法(一)——雪花算法
    HTTP状态码和支持的方法
    水平居中/垂直居中/水平垂直居中总结
    判断数组类型的4种方法
    WebSocket浅谈
    vue中使用定时器时this指向
    银行转账业务梳理
    支付那些事儿
  • 原文地址:https://www.cnblogs.com/Annetree/p/7182221.html
Copyright © 2011-2022 走看看