您的位置:首页 > 其它

hdoj1004 Let the Balloon Rise(map)

2017-06-17 22:06 281 查看
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1004

map的运用

#include<stdio.h>
#include<string>
#include<iostream>
#include<map>
using namespace std;
map<string,int>m;
int judge(string str)
{
map<string,int>::iterator it;
it=m.find(str);
if(it==m.end())return 0;
return 1;
}
int main()
{
int n,count,i,max;
string b;
while(cin>>n&&n)
{
m.clear();
while(n--)
{
cin>>b;
if(judge(b))
{
count=m[b];
m.erase(b);
m[b]=count+1;
}
else
{
m[b]=1;
}
}
max=0;
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
if((it->second)>max)
{
b=it->first;
max=it->second;
}
}
cout<<b<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  杭电 算法