解法一:Map

频率统计。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int M, N;
  5. cin >> M >> N;
  6. int tmp;
  7. map<int, int> cntMap;
  8. for (int i = 0; i < N; ++i) {
  9. for (int j = 0; j < M; ++j) {
  10. cin >> tmp;
  11. auto res = cntMap.find(tmp);
  12. if (res == cntMap.end()) {
  13. cntMap.emplace(tmp, 1);
  14. } else {
  15. res->second += 1;
  16. }
  17. }
  18. }
  19. int maxKey = 0;
  20. int maxVal = 0;
  21. for (auto &item:cntMap) {
  22. if (item.second > maxVal) {
  23. maxKey = item.first;
  24. maxVal = item.second;
  25. }
  26. }
  27. cout << maxKey << "\n";
  28. }