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 }
  • 相关阅读:
    hashlib对密码进行加密
    django中model的choices字段
    django在表发生变化后需执行命令
    djangopost请求报错:Forbidden (CSRF token missing or incorrect.)
    阻止浏览器自动填入账号和密码
    django表的models的参数及含义
    django设置静态文件
    Django的admin管理工具设置中文
    径向渐变
    文档对象的获取
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6536129.html
Copyright © 2011-2022 走看看