HDU 1004 ballons(map)

题意:输出颜色最多的那个颜色。

思路:水题一道。

#include <iostream>
#include <string>
#include <map>
#include <cstring>

using namespace std;

int main()
{
    int n ;map<string ,int > boll ;
    while(cin >> n)
    {
        if(n == 0)
        break ;
        string str,s ;

        boll.clear() ;
        for(int i = 0 ; i < n ; i ++)
        {
            cin>>str ;
            boll[str]++ ;
        }
        map<string ,int >::iterator it ;
        int maxx = 0 ;
        for(it = boll.begin() ;it != boll.end();it++)
        {
            if(it->second > maxx)
            {
                maxx = it->second ;
                s = it->first ;
            }
        }
        cout<<s<<endl ;
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3412326.html