航电oj2014:
青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。
Input
输入数据有多组,每组占一行,每行的第一个数是n(2<n<=100),表示评委的人数,然后是n个评委的打分。
Output
对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。
Sample Input
3 99 98 97
4 100 99 98 97
Sample Output
98.00
98.50
#include<iostream>
#include <iomanip>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(cin >> n) {
double a[100] = {
0 };
double avg = 0;
for(int i =0;i<n;i++){
cin >> a[i];
}
sort(a, a+n);
for (int i = 1; i < n-1; i++) {
avg += a[i];
}
avg = avg / (n - 2);
cout << setiosflags(ios::fixed) << setprecision(2);
cout << avg << endl;
}
}
航电oj2015:
Problem Description
有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。
Input
输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。
Output
对于每组输入数据,输出一个平均值序列,每组输出占一行。
Sample Input
3 2
4 2
Sample Output
3 6
3 7