hdoj 1029 Ignatius and the Princess IV

来源:互联网 发布:2017单片机前景 编辑:程序博客网 时间:2024/05/01 01:33

题目链接: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;}