zoukankan      html  css  js  c++  java
  • T5090 众数 codevs

     空间限制: 1000 KB
     题目等级 : 青铜 Bronze
    题目描述 Description

    由文件给出N个1到30000间无序数正整数,其中1≤N≤10000,同一个正整数可能会出现多次,出现次数最多的整数称为众数。求出它的众数及它出现的次数。

    输入描述 Input Description

    输入文件第一行是正整数的个数N,第二行开始为N个正整数。

    输出描述 Output Description

    输出文件有若干行,每行两个数,第1个是众数,第2个是众数出现的次数。

    样例输入 Sample Input

    12

    2  4  2  3  2  5  3  7  2  3  4  3

    样例输出 Sample Output

    2   4

    3   4

     桶排

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstdio>
     4 
     5 using namespace std;
     6 
     7 int n,x,maxn;
     8 int a[30005];
     9 
    10 int main()
    11 {
    12     scanf("%d",&n);
    13     for(int i=1;i<=n;i++)
    14     {
    15         scanf("%d",&x);
    16         a[x]++;
    17         maxn=max(maxn,a[x]);
    18     }
    19     for(int i=1;i<=30000;i++)
    20         if(a[i]==maxn)
    21             printf("%d %d
    ",i,maxn);
    22     return 0;
    23 }
    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    [POJ 2096]Collecting Bugs
    [SPOJ 375]Query on a tree
    [BZOJ 4423][AMPPZ2013]Bytehattan
    [BZOJ 2038][2009国家集训队]小Z的袜子(hose)
    [SDOI 2017]数字表格
    [NOI 2010]能量采集
    [HNOI 2014]世界树
    [HNOI 2016]序列
    [HNOI 2016]大数
    [HEOI 2014]大工程
  • 原文地址:https://www.cnblogs.com/Shy-key/p/6648216.html
Copyright © 2011-2022 走看看