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 }
  • 相关阅读:
    field_automation源码分析
    uvm设计分析——field automation
    uvm设计分析——tlm
    gedit emacs
    C语言---数据结构(内建,数组,自定义)
    C语言---选择结构和循环结构
    C语言---变量与函数
    C语言---指针
    C语言--函数
    009-多线程-锁-JUC锁-Semaphore 信号量【控制一定数量的许可(permit)的方式,来达到限制通用资源访问的目的】
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6536129.html
Copyright © 2011-2022 走看看