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
  • 相关阅读:
    13.Query for Null or Missing Fields-官方文档摘录
    海南IT互联网招聘数据简单分析
    Mongo Spark Connector中的分区器(一)
    一、Golang中的反射基本使用
    Golang中的sync.Pool对象
    Golang中的内置函数
    golang单元测试简述
    Spark Streaming数据限流简述
    Golang中类面向对象特性
    在Docker中跑Hadoop与镜像制作
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796218.html
Copyright © 2011-2022 走看看