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 }
  • 相关阅读:
    使用Xposed+JustTrustMe来突破SSL Pinning
    反编译工具
    java练习生 使用feign
    java练习生 AOP【日志】【异常处理】
    java 中string类型转Date类型和Date类型转string类型
    Metro Style App 异步简洁而不简单的异步
    Metro Style app :浏览器扩展
    用async 解放你的大脑
    Metro Style App :推送概述(二)
    Metro Style App :Framwork与WinRT(二)
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6536129.html
Copyright © 2011-2022 走看看