您的位置:首页 > 其它

hdoj 1029 Ignatius and the Princess IV

2017-08-08 15:35 344 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029

用map储存 map<数字,该数字出现的次数>s;

#include<iostream>
#include<cstdio>
#include<map>
#include<iterator>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
map<int,int>s;
map<int,int>::iterator it;  //map和迭代器  可以练习一下
int a,max1=0,ans;
while(n--)
{
scanf("%d",&a);
s[a]++;
}
for(it=s.begin();it!=s.end();it++)
{
if(max1<it->second)      //it->first相当于数组下标
{                        //it->second相当于当前下表所代表的值
max1=it->second;
ans=it->first;
}
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm hdoj