zoukankan      html  css  js  c++  java
  • HDU 1004 Let the Balloon Rise(map应用)

    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<iostream>
     2 #include<cstdio>
     3 #include<queue>
     4 #include<vector>
     5 #include<cstring>
     6 #include<string>
     7 #include<algorithm>
     8 #include<map>
     9 using namespace std;
    10 
    11 
    12 int main()
    13 {
    14     int n;
    15     while(~scanf("%d",&n)&&n)
    16     {
    17         map<string,int>m;//声明容器
    18         map<string,int>::iterator it;//声明迭代器
    19         string color;
    20         for(int i=0;i<n;i++)
    21         {
    22             cin>>color;
    23             m[color]++;
    24         }
    25         int max=0;
    26         string ans;
    27         for(it=m.begin();it!=m.end();it++)
    28         {
    29             if(it->second>max)
    30             {
    31                 max=it->second;
    32                 ans=it->first;
    33             }
    34         }
    35         cout<<ans<<endl;
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    shell 指定范围产生随机数
    shell脚本比较两个数大小
    Shell 脚本实现随机抽取班级学生
    linux通过挂载系统光盘搭建本地yum仓库的方法
    kuberenetes 上使用helm部署rancher如何卸载干净
    Windows 下 左Ctrl和Caps交换
    C#笔记 -- 协变、逆变
    Python 读取window下UTF-8-BOM 文件
    生成命令行程序使用脚本
    ffmpeg 命令小记
  • 原文地址:https://www.cnblogs.com/Annetree/p/7182221.html
Copyright © 2011-2022 走看看