解法一:Map
频率统计。
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, N;
cin >> M >> N;
int tmp;
map<int, int> cntMap;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cin >> tmp;
auto res = cntMap.find(tmp);
if (res == cntMap.end()) {
cntMap.emplace(tmp, 1);
} else {
res->second += 1;
}
}
}
int maxKey = 0;
int maxVal = 0;
for (auto &item:cntMap) {
if (item.second > maxVal) {
maxKey = item.first;
maxVal = item.second;
}
}
cout << maxKey << "\n";
}