Luogu brush questions C++ language | P5726 score

Learn C++ from a baby! Record the questions in the process of Luogu C++ learning and test preparation, and record every moment.

Attached is a summary post: Luogu Brush Questions C++ Language | Summary


【Description】

Now there are  n ( n ≤ 1000) judges scoring the contestants, with scores ranging from 0 to 10. It is necessary to remove the highest score and the lowest score (if there are multiple highest or lowest scores, only one needs to be removed), and the average of the remaining scores is the player's score. Now enter the number of judges and their scores, please output the final score of the contestants, accurate to 2 decimal places.

【enter】

The first line inputs a positive integer  n , indicating that there are  n  judges.

Enter  n  positive integers in the second line, and the  i-  th positive integer represents  the score of the i-  th judge.

【Output】

Output a line with a two-digit decimal, indicating the player's final score.

【Input sample】

5 9 5 6 8 9

【Example of output】

7.67

【Code Explanation】

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,t,max,min,sum=0;
    cin >> n;
    cin >> t;
    max = t;
    min = t;
    sum += t;
    for (int i=1; i<n; i++) {
        cin >> t;
        sum += t;
        if (max < t) max = t;
        if (min > t) min = t;
    }
    double ans = 1.0 * (sum-max-min)/(n-2);
    printf("%.2f", ans);
    return 0;
}

【operation result】

5
9 5 6 8 9
7.67

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132642025