【2-1】众数问题

描述

【题解】

unordered_map跟直接用数组差不多。

【代码】

#include <cstdio>
#include <unordered_map>
using namespace std;

const int N= 1e7;

int dic[N+10];
int n,ma,man;

int main(){
    //freopen("D:\mode10.in","r",stdin);
    scanf("%d",&n);
    for (int i = 1;i <= n;i++){
        int x;
        scanf("%d",&x);
        dic[x]++;
        if (dic[x]>ma){
            ma = dic[x];
            man = x;
        }
    }
    printf("%d %d
",man,ma);
    return 0;
}

原文地址:https://www.cnblogs.com/AWCXV/p/11629501.html