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
[Title description]
n ( n ≤100) students participated in the singing competition and received scores from m ( m ≤20) judges, with scores ranging from 0 to 10 points. The student's score is the average of the remaining m −2 scores after removing the highest score and the lowest score from the judges' scores. What is the score of the student with the highest score? Score to 2 decimal places.
【enter】
The first line contains two integers n and m . Next n lines, each line contains m integers, indicating the score.
【Output】
Output the score of the student with the highest score, keeping two decimal places.
【Input sample】
7 6
4 7 2 6 10 7
0 5 0 10 3 10
2 6 8 4 3 6
6 3 6 7 5 8
5 9 3 3 8 1
5 9 9 3 2 0
5 8 0 4 1 10
【Output sample】
6.00
[Detailed code explanation]
#include <bits/stdc++.h>
using namespace std;
double judge(int m) {
int max, min, sum=0, tmp;
double ans;
cin >> tmp;
max = tmp;
min = tmp;
sum += tmp;
for (int i=2; i<=m; i++) {
cin >> tmp;
if (tmp>max) max = tmp;
if (tmp<min) min = tmp;
sum += tmp;
}
sum -= max+min;
ans = 1.0 * sum / (m-2);
return ans;
}
int main()
{
int n, m;
double ans = -1, tmp;
cin >> n >> m;
for (int i=1; i<=n; i++) {
tmp = judge(m); //计算某一名同学评分
if (ans < tmp) {
ans = tmp;
}
}
printf("%.2f", ans);
return 0;
}
【operation result】
7 6
4 7 2 6 10 7
0 5 0 10 3 10
2 6 8 4 3 6
6 3 6 7 5 8
5 9 3 3 8 1
5 9 9 3 2 0
5 8 0 4 1 10
6.00