/*
題意:給一個(gè)列、行的二維矩陣,統(tǒng)計(jì)最多數(shù)字
解題:
1、用一個(gè)哈希二維數(shù)組唄,
2、但是如何統(tǒng)計(jì)最大呢,遍歷?會(huì)超時(shí)嗎,
learn && wrong:
1、iterator寫錯(cuò),以及兩個(gè)冒號(hào)是放在變量前
2、題意很好,一個(gè)數(shù)字,一個(gè)映射次數(shù),
3、查找,find跟end.()結(jié)合,這招出現(xiàn)很多次了
4、查找最大,max為0,然后it->second做比較
*/
#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int main()
{
int n,m,col;
scanf("%d%d", &n,&m); //行與列
map<int,int> count; //數(shù)字與出現(xiàn)的次數(shù)map映射
for(int i = 0;i < n;++i){
for(int j = 0;j < m;++j){
scanf("%d",&col); //輸入數(shù)字
if(count.find(col) != count.end()) count[col]++; //若已經(jīng)存在,則次數(shù)+1 ?。。? else count[col] = 1; //若不存在,則次數(shù)置為1
}
}
int k = 0,max = 0; //最大數(shù)字以及出現(xiàn)的次數(shù) ?。。? for(map<int,int>::iterator it = count.begin();it != count.end();++it){
if(it->second > max){
k = it->first; //最大的數(shù)字
max = it->second; //出現(xiàn)的次數(shù);
}
}
cout<<k<<endl;
return 0;
}