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
  • 相关阅读:
    mapreduce 本地调试需要注意的问题
    socket-----爬虫&&文件传输
    多个地点ping服务器
    linux grep命令详解
    关于真多核和加多核&线程由哪几部分组成
    内存溢出和内存泄漏
    指针和引用的区别
    Doxygen的使用,配置及实例
    【转】doxygen+graphviz生成工程中的类继承树及函数调用图
    转载--void指针(void *的用法)
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796218.html
Copyright © 2011-2022 走看看