zoukankan      html  css  js  c++  java
  • HDOJ 1004

    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 <cstdio>
     2 #include <cstdlib>
     3 #include <iostream>
     4 #include <string>
     5 #include <map>
     6 
     7 using namespace std;
     8 
     9 map<string,int> my_Map;
    10 pair<string,int> mc;
    11 
    12 int main(){
    13     int n;
    14     string bl;
    15     while(cin>>n){
    16         if(!n)break;
    17         map<string,int>::iterator itr;
    18         while(n--){
    19             cin>>bl;
    20             itr = my_Map.find(bl);
    21             if(itr == my_Map.end()){
    22                 my_Map[bl] = 1;
    23             }else{
    24                 int c = my_Map[bl];
    25                 my_Map[bl] = ++c;
    26             }
    27         }
    28         mc.first = my_Map.begin()->first;
    29         mc.second = my_Map.begin()->second;
    30         itr = my_Map.begin();
    31         for(++itr;itr!=my_Map.end();++itr){
    32             if(itr->second>mc.second){
    33                 mc.first = itr->first;
    34                 mc.second = itr->second;
    35             }
    36         }
    37         cout<<mc.first<<endl;
    38         my_Map.clear();
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    知识的本质
    福克斯保养注意事项及驾驶技巧
    转 网络编程
    Linux系统下安装 apache2.4的过程
    代码静态检查工具PCLint运用实践
    gcc编译系统
    量子计算机:决胜21世纪的利器
    关于ETL工具、方案的认识
    《HTTP: The Definitive Guide》读书笔记
    ArrayList(转用法)
  • 原文地址:https://www.cnblogs.com/lueagle/p/6359900.html
Copyright © 2011-2022 走看看