• 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 }
  • 相关阅读:
    不过的小东东
    基础练习 特殊回文数
    基础练习 特殊回文数
    基础练习 特殊回文数
    web.input()与web.data()函数比较
    web.input()与web.data()函数比较
    web.input()与web.data()函数比较
    MFC 服务管理
    Fedora Documentation
    Centos7 安装vnc
  • 原文地址:https://www.cnblogs.com/lueagle/p/6359900.html
Copyright © 2020-2023  润新知