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 }
  • 相关阅读:
    在Mac电脑编译c51程序
    Unix程序员的Win10二三事
    macOS webview编程
    Day 6 文件属性与命令执行流程
    Day 5文件管理—三剑客的了解
    Day4 文件管理-常用命令
    Day3 目录结构及文件管理
    Day 2 Bash shell 认识
    Day 1 linux系统的发展史与虚拟机的安装过程
    【Offer】[66] 【构建乘积数组】
  • 原文地址:https://www.cnblogs.com/lueagle/p/6359900.html
Copyright © 2011-2022 走看看