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 }
  • 相关阅读:
    迈瑞医疗招聘-软件测试工程师
    软件自动化测试开发-3期开班啦
    luogu P2744 [USACO5.3]量取牛奶Milk Measuring
    luogu P2515 [HAOI2010]软件安装
    luogu P2423 双塔
    luogu P1651 塔
    luogu P1489 猫狗大战
    luogu P3092 [USACO13NOV]没有找零No Change
    luogu P3800 Power收集
    luogu P2949 [USACO09OPEN]工作调度Work Scheduling
  • 原文地址:https://www.cnblogs.com/lueagle/p/6359900.html
Copyright © 2011-2022 走看看