题目描述
n(n\le 100)n(n≤100) 名同学参加歌唱比赛,并接受 m(m\le 20)m(m≤20) 名评委的评分,评分范围是 0 到 10 分。这名同学的得分就是这些评委给分中去掉一个最高分,去掉一个最低分,剩下 m-2m−2 个评分的平均数。请问得分最高的同学分数是多少?评分保留 2 位小数。
输入格式
第一行两个整数 n,mn,m。 接下来 nn 行,每行各 mm 个整数,表示得分。
输出格式
输出分数最高的同学的分数,保留两位小数。
分析:
设计一个计算总成绩的函数,将最高的总分保留,输出最高的。
#include<bits/stdc++.h>
using namespace std;
int a[20];
double maxx = 0.0;
void c(int m) {//计算总成绩
double sum = 0.0;
sort(a, a + m);
for (int i = 1; i < m - 1; i++) {//去掉最高分和最低分
sum += a[i];
}
maxx = max(sum, maxx);//将总分高的给maxx
}
int main() {
int m, n;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[j];
}
c(m);
}
cout << setiosflags(ios::fixed) << setprecision(2);
cout << maxx / (m - 2);
return 0;
}