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 }
  • 相关阅读:
    node入门(一)——安装
    移动web开发基础(二)——viewport
    移动web开发基础(一)——像素
    关于min-height:100%的解决办法
    用类与原型写一个组件(三)——学习笔记
    用类与原型写一个组件(二)——学习笔记
    用类与原型写一个组件(一)——学习笔记
    js类、原型——学习笔记
    Android 常用RGB值及名称
    AES加密示例
  • 原文地址:https://www.cnblogs.com/lueagle/p/6359900.html
Copyright © 2011-2022 走看看