【2-1】众数问题

时间:2019-10-07 10:30:50   收藏:0   阅读:112

描述

【题解】


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\n",man,ma);
    return 0;
}

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!