首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HDOJ 1004 Let the Balloon Rise (地图)

2012-09-17 
HDOJ 1004 Let the Balloon Rise (map)http://acm.hdu.edu.cn/showproblem.php?pid1004题意:求出现次数最

HDOJ 1004 Let the Balloon Rise (map)

http://acm.hdu.edu.cn/showproblem.php?pid=1004

题意:求出现次数最多的颜色。

思路:用map存储颜色和出现次数,然后遍历一遍查找出现次数最多的即可。

#include<iostream>#include<string>#include<map>using namespace std;int main(){    int n;    map <string,int> color;    while(cin>>n&&n)    {        color.clear();        while(n--)        {            string ip;            cin>>ip;            if(color.find(ip)!=color.end())                color[ip]++;            else                color[ip]=1;        }        map<string,int>::iterator p;        string op;        int max=0;        for(p=color.begin();p!=color.end();p++)        {            if(p->second>max)            {                op=p->first;                max=p->second;            }        }        cout<<op<<endl;    }    return 0;}

热点排行