您的位置:首页 > 其它

hdoj 1004 Let the Balloon Rise(map)

2017-11-19 21:10 381 查看


Let the Balloon Rise(链接)

Sample Input

5
green
red
blue
red
red
3
pink
orange
pink
0

 

Sample Output

red
pink

 
输出出现次数最多的颜色  用map存一下就好了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

int main()
{
map<string,int> B;
string Color,Max;
int n;
while(~scanf("%d",&n)&&n!=0)
{
B.clear();
while(n--)
{
cin>>Color;
B[Color]++;
}
int max=0;
map<string,int>::iterator it;   //迭代器
for(it=B.begin();it!=B.end();it++)
{
if(it->second>max)
{
max=it->second;    //只能用  ->  不可以用dian点.
Max=it->first;
}
}
cout<<Max<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: