首页 > 学院 > 开发设计 > 正文

【杭电OJ从头刷】HDU1004

2019-11-11 04:18:59
字体:
来源:转载
供稿:网友

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

利用map容器可以很容易的解决,同样也可以考虑结构体或者二维数组的方法,有兴趣的可以自己实现一下。

#include<iostream>#include<map>using namespace std;int main(){	int n,max;	map<string , int> ballon;	string color;	string MaxColor;	while(cin>>n)	{		if(n==0)		{			return 0;		}		ballon.clear();		for(int i=0;i<n;i++)		{			cin>>color;			ballon[color]++;		}		map<string, int>::iterator it;		max=0;		for(it=ballon.begin();it!=ballon.end();it++)		{			if(it->second>max)			{				max = it->second;				MaxColor = it->first;			}		}		cout<<MaxColor<<endl;	}}注意:记得每次进行操作之前先把容器清空,否则上次运行的结果会影响下一次的运算。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表