码迷,mamicode.com
首页 > 其他好文 > 详细

map容器

时间:2014-08-04 21:16:37      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   io   for   

试题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004

试题分析:本题如果使用预定义的map类会非常的方便

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

using namespace std;

int n,maxNum;
string a;
string maxColor;
map<string,int> ballon;
int main()
{

    while(cin>>n)
    {

        if(!n)break;
        maxNum = 0;
        ballon.clear();
        
       for(int i=0;i<n;i++){

    cin>>a;
                ballon[a]++;
        }
        map<string,int>::iterator ite;
        for(ite = ballon.begin();ite!=ballon.end();ite++){
            if(ite->second >maxNum){
                maxNum = ite->second;
                maxColor = ite->first;
            }
        }
        cout<<maxColor<<endl;
    }
    return 0;
}

 

map容器,布布扣,bubuko.com

map容器

标签:style   blog   http   color   使用   os   io   for   

原文地址:http://www.cnblogs.com/tianxia2s/p/3890866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!