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

    Let the Balloon Rise

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 145541    Accepted Submission(s): 57738

     

    Problem Description

    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

    用了STL中的map,确实方便一些,题目很水。

    AC代码:

     1 #include<iostream>
     2 #include<string>
     3 #include<algorithm>
     4 #include<iomanip>
     5 #include<cmath>
     6 #include<map>
     7 using namespace std;
     8 int main()
     9 {
    10     int N,i;
    11     string str;
    12     map<string,int>balloon;
    13     while(cin>>N&&N!=0)
    14     {
    15            balloon.clear() ;
    16            for(i=1;i<=N;i++) 
    17            {
    18                    cin>>str;
    19             if(balloon.count(str)) balloon[str]++;
    20             else balloon[str]=1;      
    21         }
    22         map<string,int>::iterator iter=balloon.begin();
    23         int max=0;
    24         for(;iter!=balloon.end();iter++) 
    25         if(iter->second>max)
    26         {
    27             max=iter->second;
    28             str=iter->first;
    29         }
    30         cout<<str<<endl;
    31     } 
    32 }
    33  
    View Code
  • 相关阅读:
    python 如何把在字符串里面的名字变成变量,进行复制
    2017-05-30 英语
    RYU 中如钩构建TCP数据包,设置ACK等标志
    Arch linux LXR 安装过程
    ubuntu如何配置lxr
    2017-05-27 英语
    Emacs学习笔记:移动
    9.特殊矩阵的压缩存储
    13.链路层设备
    9.CSMA_CD协议
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796218.html
Copyright © 2011-2022 走看看