zoukankan      html  css  js  c++  java
  • zoj 2104 Let the Balloon Rise

    Let the Balloon Rise

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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 <map>
     3 #include <string>
     4 #include <cstdio>
     5 using namespace std;
     6 int main(){
     7     int n;
     8     string s, str;
     9     map<string, int> mp;
    10     while(cin >> n){
    11         if(n == 0){
    12             break;
    13         }
    14         mp.clear();
    15         for(int i = 0; i < n; i++){
    16             cin >> s;
    17             if(mp.find(s) != mp.end())
    18                 mp[s]++;
    19             else
    20                 mp[s] = 1;
    21         }
    22         map<string, int>::iterator it = mp.begin();
    23         int max = 0;
    24         while(it != mp.end()){
    25             if(it->second > max){
    26                 max = it->second;
    27                 str = it->first;
    28             }
    29             it++;
    30         }
    31         printf("%s
    ", str.c_str());
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    架构师维度理解 程序=数据+算法
    vuejs 中 select 动态填充数据,后台的数据
    vuejs 的错误代码,有助于理解
    graphviz 绘制架构图
    graphviz 布局和子图,表格教程
    graphviz layer 教程(非布局)
    待学习
    Linux进程管理
    TCP连接的11种状态,三次握手四次挥手原因
    Linux基本命令使用(三)
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6536129.html
Copyright © 2011-2022 走看看