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
  • 相关阅读:
    插入排序(二)
    选择排序(一)
    (转)示例化讲解RIP路由更新机制
    Css元素居中设置
    (转)盒子概念和DiV布局
    (转)浅析CSS——元素重叠及position定位的z-index顺序
    (转)Java中的static关键字解析
    (转)字符串循环移位
    linux把某个文件拷贝到不同的目录下面
    linux中查找文件并合并文件
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796218.html
Copyright © 2011-2022 走看看