PAT_1054. The Dominant Color

来源:互联网 发布:电子科技大学网络教育学费 编辑:程序博客网 时间:2024/06/05 14:43
////  main.cpp//  PAT_1054. The Dominant Color////  Created by wjq on 17/5/15.//  Copyright © 2017年 wjq. All rights reserved.//#include <iostream>#include <vector>#include <map>using namespace std;int N,M,temp;vector<int> v;map<int,int> m;int main(int argc, const char * argv[]){    cin>>N>>M;    for(int i=0;i<N*M;i++)    {        cin>>temp;        if(m.find(temp)==m.end())            m[temp]=1;        else            m[temp]++;        v.push_back(temp);    }    for(int i=0;i<v.size();i++)    {        if(m[v[i]]>M*N/2)        {            cout<<v[i];            break;        }    }    return 0;}