1054 The Dominant Color (20point(s)) Easy only once

基本思想:

无,简单的排序问题,注意pair排序的另解;

 

关键点:

无;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
using namespace std;

int m, n;
map<int, int>mp;


int main() {
    cin >> m >> n;
    int a;
    for (int i = 0; i < m*n; i++) {
        cin >> a;
        if (mp.find(a) == mp.end()) {
            mp[a] = 1;
        }
        else {
            mp[a]++;
        }
    }
    int max = 0;
    map<int, int>::iterator fin;
    for (map<int,int>::iterator it = mp.begin(); it != mp.end(); it++) {
        if (it->second > max) {
            max = it->second;
            fin = it;
        }
    }
    if (fin->second > m*n / 2) {
        cout << fin->first;
    }
    return 0;
}

 

posted @ 2020-02-21 17:05  暮云林凌  阅读(127)  评论(0)    收藏  举报