码迷,mamicode.com
首页 > 其他好文 > 详细

PAT:1054. The Dominant Color (20) AC(map法)

时间:2015-03-11 00:26:16      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<map>
using namespace std;
const int MAX=0x3fffffff;
int main()
{
  int m,n;
  map<int,int> count;        //数字与出现次数的map映射
  scanf("%d%d",&m,&n);
  for(int i=0 ; i<n ; ++i)
  {
    for(int j=0 ; j<m ; ++j)
    {
      int tmp;
      scanf("%d",&tmp);
      if(count.find(tmp)!=count.end())  //存在,次数+1
        ++count[tmp];
      else                //不存在,次数设为1
        count[tmp]=1;
    }
  }
  int ans=-1,MAXtmp=-1;
  for(map<int,int>::iterator it=count.begin() ; it!=count.end() ; ++it)
  {
    if(it->second>MAXtmp)          //【skill】map映射的第一第二位置的使用
    {
      ans=it->first;
      MAXtmp=it->second;
    }
  }
  printf("%d\n",ans);
  return 0;
}

PAT:1054. The Dominant Color (20) AC(map法)

标签:

原文地址:http://www.cnblogs.com/Evence/p/4328692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!