首页 > 其他 > 详细

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

时间:2015-03-11 00:24:24      阅读:337      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!