hdoj 1029 Ignatius and the Princess IV

題目鏈接: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;
}



發佈了50 篇原創文章 · 獲贊 3 · 訪問量 8754
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章