HDU 2014 青年歌手大奖赛_评委会打分

http://acm.hdu.edu.cn/showproblem.php?pid=2014

Problem Description
青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。
 
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 <bits/stdc++.h>

using namespace std;

int a[111];

int main()
{
    int n;
    double ave;
    while(cin>>n)
    {
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            for(int j=i;j>=2;j--)
            {
                if(a[j]<=a[j-1])
                swap(a[j],a[j-1]);
            }
        }
        for(int i=2;i<=n-1;i++)
        {
            sum+=a[i];
        }
        ave=sum*1.0/(n-2);
        printf("%.2f
",ave);
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9219587.html