题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768

感觉map太强了,完全可以代替哈希表,之前哈希表那块写的什么玩意。。

代码

  1. #include<map>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<iostream>
  5. using namespace std;
  6. map<int, int> arr;
  7. int main(){
  8. int m, n, temp;
  9. int ans, max = -1;
  10. scanf("%d%d", &m, &n);
  11. for(int i = 0; i < m; i++){
  12. for(int j = 0; j < n; j ++){
  13. scanf("%d",&temp);
  14. if(arr.find(temp)==arr.end()){
  15. arr[temp] = 0;
  16. } else {
  17. arr[temp]++;
  18. }
  19. if(arr[temp] > max) ans = temp;
  20. }
  21. }
  22. printf("%d",ans);
  23. }