11.3 作业 Problem L: 数字统计

    xiaoxiao2021-12-12  12

    Description

    给出一些数字,统计出现最多的数字的次数。

    Input

    输入中第一行包含一个N,0 < N <= 500000。

    后面N行每行包含一个数字k,0<=k<=200000。

    Output

    输出出现次数最多的数字的个数。

    Sample Input

    5 1 1 2 3 4

    Sample Output

    2

    思路:

    相当流氓的做法。开一个数组。因为只有0-9会输入。输入一个数n  相应的下标对应的a[n]++。然后判断最大值。

    一层循环即可完成。

    代码:

    #include<stdio.h> int main() { int i,N,max=0,s,b[200001]; scanf("%d",&N); for (i=0;i<N;i++) { scanf("%d",&s); b[s]++; if(b[s]>max) max=b[s]; } printf("%d\n",max); }

    转载请注明原文地址: https://ju.6miu.com/read-900035.html

    最新回复(0)