• 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
  • 相关阅读:
    十二月第二周学习进度条
    《UML大战需求分析》阅读笔记4
    十二月第一周学习进度条
    十一月第四周学习进度条
    十一月第三周学习进度条
    十一月第二周学习进度条
    制作验证码(转)
    阅读笔记04
    课堂作业-购书问题
    阅读笔记03
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796218.html
Copyright © 2020-2023  润新知