• 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 }
  • 相关阅读:
    web print
    datediff
    Typical AJAX
    sql中构建sql语句,再exec这条SQL语句
    ASP.NET中将数据输出到WORD、EXCEL、TXT、HTM
    sql中添加单引号
    sql语句批处理
    日期分组
    异步线程
    电脑内存大有什么好处?
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6536129.html
Copyright © 2020-2023  润新知