C++ STL map A1054 The Dominant Color(20)

 

 

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int maxn = 480005;//最大学生人数
map<int,int> temp;
int main(){
    int m,n;
    scanf("%d%d",&m,&n);
    for(int i=0;i<n;++i){
        for(int j = 0;j<m;++j){
            int t;
            scanf("%d",&t);
            //map<int,int>::iterator it;
            if(temp.find(t) != temp.end()){
              temp[t]++;  
            }else{
                temp[t] = 1;
            }
        }
    }
    map<int,int>::iterator it;
    int max = 0;
    int result = 0;
    for(it = temp.begin();it != temp.end();++it){
        if(it->second > max){
            max = it->second;
            result = it->first;
        }
    }
    cout<<result<<endl;
    system("pause");
    return 0;
} 
posted @ 2020-01-17 10:22  JasonPeng1  阅读(87)  评论(0编辑  收藏  举报