1 solutions

  • 0
    @ 2023-1-21 20:47:26
    #include <bits/stdc++.h>
    using namespace std;
    /*
    a数组存储读入的每个数
    b数组表示每个读入的数出现的次数 
    */
    int main()
    {
        int n,a[10900],b[110];
        double sum=0;
        cin >> n;
        for(int i=1;i<=n;i++)
        {
            cin >> a[i];
            b[a[i]]++;
            sum += a[i];
        }
        cout << fixed << setprecision(2) << 1.0*sum/n << " ";
        //众数:计数数组的最大数下标 
    	int max=0;
        for(int i=1;i<=100;i++)
        {
            if(b[i] > b[max]) max = i;
        }
        //众数: 
        cout << max << " ";
        //中位数 
        sort (a+1,a+n+1);
        if(n%2==1) cout << fixed << setprecision(1) <<a[n/2+1]*1.0;
            else cout << fixed << setprecision(1) <<(a[n/2]+a[n/2+1])/2.0;
     return 0;  
    }
    
    
    • 1

    【入门】求N个整数的平均数、众数和中位数

    Information

    ID
    519
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    10
    Tags
    # Submissions
    4
    Accepted
    3
    Uploaded By