HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)

Problem Description
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business.
One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance.

Basically, scores given to a contestant’s performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer.

You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.

Input
The input consists of a number of datasets, each corresponding to a contestant’s performance. There are no more than 20 datasets in the input.

A dataset begins with a line with an integer n, the number of judges participated in scoring the performance (3 ≤ n ≤ 100). Each of the n lines following it has an integral score s (0 ≤ s ≤ 1000) marked by a judge. No other characters except for digits to express these numbers are in the input. Judges’ names are kept secret.

The end of the input is indicated by a line with a single zero in it.

Output
For each dataset, a line containing a single decimal integer indicating the score for the corresponding performance should be output. No other characters should be on the output line.

Sample Input
3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0

Sample Output
342
7
300
326

分数都是整数!平均分也要是整数!
评委打分,去掉一个最高分,去掉一个最低分,求剩下的平均分!
不用四舍五入。直接舍去小数位就可以。

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            if(n<=0){
                return ;
            }
            int sum =0;
            int min = sc.nextInt();
            int max=min;
            sum=max;
            int b;
            for(int i=1;i<n;i++){
                b = sc.nextInt();
                if(b>max){
                    max=b;
                }
                if(b<min){
                    min=b;
                }
                sum+=b;
            }
            sum=sum-min-max;
            System.out.println((int)(sum/(n-2)));
        }
    }
}
时间: 2024-07-31 06:11:15

HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)的相关文章

excel怎么求平均值的方法

excel怎么求平均值?excel平均值相关的函数有AVERAGEIFS.AVERAGE函数.SUBTOTAL函数.本文以一个综合实例来进一步认识excel怎么求平均值. 如果刚接触excel不久,对公式不熟悉的话,可以使用单个的函数来完成,比如求平均值,在I2输入公式:=AVERAGE(B2:E2),下拉复制就求出甲乙丙丁的平均值了. 如果对函数公式嵌套理解能力很好的话,也可以使用一个区域数组一次性完成最大值.最小值.平均值的计算. 究竟excel怎么求平均值呢?以上图为例,选中G2:I5区域

Excel2010函数求和,求平均值

在excel中经常会用的一些数据的求和.求平均值的命令,比如学生成绩的总分汇总和求班级的平均分的情况.那么怎么来进行操作呢?在Excel2010用函数自动表内求和,求平均值运算的方法如下: 步骤一:首先要知道求和的函数是SUM.如图所示对下面的数据进行求和求平均值的计算. 步骤二:在总分的单元格(B12)上,输入函数"=SUM(B2:B11)"为什么要输入这个函数值呢.sum是求和函数值,后面的是从B2单元格到B11单元格的总分值.相信这样总该明白为什么输入的B2:B11了吧,如果你求

巧用WPS表格移动版Average函数求平均值

对于经常接触表格的朋友来说,想必他们都跟阿mo一样,常常用求和.求差.求积.求平均值等公式对表格数据进行运算.而在统计.调研.教育等领域,求平均值是Excel表格最常用的公式,下面阿mo就用WPS移动版为大家讲解一个实例. 首先,确保手机或平板中装有WPS移动版,运行后打开事先已经准备好的Excel文档.当然,你也可以借助WPS移动版新建Excel文档再作编辑.这里以阿mo打开的一张成绩表为例,上面有各门功课的成绩,要得出各学生的平均分数,此时就要用到WPS移动版的"求平均值"功能,其

Excel自动求平均值的函数公式

在制作表格的过程中,我们可能会用Excel来对数据进行各种运算,如:求和.求差.求积等公式,来完成我们的运算.在前面几课中我们已经基本的讲解了各种运算的函数公式,本篇再来说下在Excel表格中如何求平均值.我们在制作一份成绩表排名的时候,知道了各科成绩,需要求出成绩的平均值,我们该如何来完成呢?下面就看看Word联盟为大家演示吧! 首先,这里是一份成绩表,上面有各门功课的成绩,我们要求出平均分数. ①将光标定位到"平均分"下面一个单元格中,然后点击"插入函数"按钮,

excel表格中如何使用函数求平均值?

  excel表格中如何使用函数求平均值?           步骤 1.打开表格,锁定要求平均值的单元格 2.选定单元后,点击表格上方 "公式",出现下图界面 3.在公式一栏中,找到自动求和图标,点击图标,出现下拉链,找到"平均值". 4.点击"平均值",出现如下函数公式,虽然看着比较乱,但是不要慌,我们离成功越来越近啦. 5.不管上图看着怎样乱,我们只要淡定的同时按下键盘上"Ctrl"和"Enter"健

excel去掉最大值和最小值后求平均值的公式

  在一些竞赛活动中,经常看到裁判现场打分的情况,为了保证竞赛公平,通常在所有裁判给出的分数中去掉一个或几个最高和最低分,然后用剩余的分数取平均得到参赛选手的最后得分.这一点在Excel中用TRIMMEAN函数就可以轻松实现.TRIMMEAN函数先从数据集的头部和尾部除去一定百分比的数据点,然后再求平均值.其语法是: TRIMMEAN(array,percent) Array 为需要进行整理并求平均值的数组或数值区域. Percent 为计算时所要除去的数据点的比例.例如,如果percent =

Excel自动求平均值函数公式

  在制作表格的过程中,我们可能会用Excel来对数据进行各种运算,如:求和.求差.求积等公式,来完成我们的运算.在前面几课中我们已经基本的讲解了各种运算的函数公式,本篇再来说下在Excel表格中如何求平均值.我们在制作一份成绩表排名的时候,知道了各科成绩,需要求出成绩的平均值,我们该如何来完成呢? 首先,这里是一份成绩表,上面有各门功课的成绩,我们要求出平均分数. ①将光标定位到"平均分"下面一个单元格中,然后点击"插入函数"按钮,如下图红色区域便是; ②在弹出的

【c语言】2维数组求平均值,指针出问题了

问题描述 [c语言]2维数组求平均值,指针出问题了 double average(double (*p)[],double *q,int n,int m) { int i,j; double NU,AE;//每列总和与每行总和 for(i=0;i<n;i++) { for(NU=0,j=0;j<m;j++) { NU+=(*p+i)[j];//每列的和 } q[i]=NU/m;//每行的平均值 AE+=NU;//每行的和 } return AE/(n*m);//总平均值 } 第一行的平均值没错

c++-C语言,请问怎么调用这个求平均值的函数?

问题描述 C语言,请问怎么调用这个求平均值的函数? 解决方案 图看不清,我给你写了一个 float avg(int n, ...) { va_list argp; va_start(argp, n); int para; int i = 0, sum = 0; while (i++ < n) { para = va_arg(argp, int); sum += para; } va_end(argp); return sum / float(n); } int main() { float n