//map做法http://blog.youkuaiyun.com/asure__cpp/article/details/8727340
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
int n, i;
map<string, int>m;
while(scanf("%d", &n) != EOF && n)
{
m.clear();
string color, maxcolor;
int max = 0;
while(n--)
{
cin >> color;
m[color]++;
}
map<string, int>::iterator m_Iter;
for( m_Iter = m.begin(); m_Iter != m.end(); m_Iter++ )
{
if(max < m_Iter->second)
max = m_Iter->second, maxcolor = m_Iter->first;
}
cout << maxcolor << endl;
}
return 0;
}hdu 1004 Let the Balloon Rise
最新推荐文章于 2021-06-24 22:53:24 发布
本文介绍了一种使用C++和标准模板库(STL)中的map容器来统计不同颜色出现次数的方法。通过读取输入的颜色字符串,并利用map容器自动处理重复颜色的计数,最终找出出现次数最多的颜色。
316

被折叠的 条评论
为什么被折叠?



