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 }
  • 相关阅读:
    MySQL 性能调优之索引
    MySQL 性能调优之存储引擎
    MySQL数据类型优化—整数类型优化选择
    MySQL数据性能优化-修改方法与步骤
    MySQL设计SQL语句优化规范
    MySQL索引的设计、使用和优化
    MySQL的SQL语句优化-group by语句的优化
    SQL性能优化-order by语句的优化
    MySQL查询优化注意下面的四个细节
    优化MySQL性能的几种方法-总结
  • 原文地址:https://www.cnblogs.com/Annetree/p/7182221.html
Copyright © 2011-2022 走看看