
AC代码
#include<stdio.h>
#include<math.h>
int main(){
int n,m;
float g1=0,g2,temp;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
scanf("%f",&g2);
int cnt=0,sum=0,Max=-1,Min=101;//cnt记有效个数,sum记求和,Max记最大值,Min记最小值
for(int j=0;j<n-1;j++){
scanf("%f",&temp);
if(temp<0||temp>m)continue;
cnt++;
sum+=temp;
if(temp>Max)Max=temp;
if(temp<Min)Min=temp;
}
g1=(sum-Max-Min)/(cnt-2);//g1是减去一个最大值和一个最小值的求平均
int av=round((g1+g2)/2);
printf("%d\n",av);
}
return 0;
}
计算平均值的C++程序
该C++代码用于读取n组数据,每组包含一个浮点数g2和n-1个在0到m之间的浮点数temp。它计算去除最大值和最小值后的平均值g1,并将g1和g2的平均值四舍五入后输出。
172

被折叠的 条评论
为什么被折叠?



