1054. The Dominant Color (20)

来源:互联网 发布:windows 10不能打字 编辑:程序博客网 时间:2024/06/18 04:27
#include<cstdio>#include<string>#include<map>#include<iostream>using namespace std;int main(){  map<int,int> mp;  int M,N;  int color,MAX=0,k=0;  scanf("%d%d",&M,&N);  for(int i=0; i<N; i++)  {    for(int j=0; j<M; j++)    {      scanf("%d",&color);           //直接加有危险!!!      //mp[color]++;        if(mp.find(color) != mp.end())        mp[color]++;      else        mp[color] = 1;    }  }  for(map<int,int>::iterator it = mp.begin(); it!=mp.end(); it++)  {    if(it->second>MAX)    {      k = it->first;      MAX = it->second;    }  }  printf("%d",k);  return 0;}

0 0
原创粉丝点击