首页 > 其他 > 详细

【2-1】众数问题

时间:2019-10-07 10:30:50      阅读:112      评论:0      收藏:0      [点我收藏+]

描述

【题解】


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;
}

【2-1】众数问题

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!