wusiyuan @ 2020-09-05 14:34:20
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a[101],d=-1,x=100,g=0;
float h=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
if(a[i]>d){
d=a[i];
}
if(a[i]<x){
x=a[i];
}
}
for(int i=1;i<=n;i++){
g+=a[i];
}
g=g-x-d;
h=h+g/(n-2);
printf("%.2f",h);
return 0;
}
by AdventureExtremeX @ 2020-09-05 14:39:17
赋值 h 为啥还要h+
/yiw
by sheeplittlecloud @ 2020-09-05 14:41:01
@wusiyuan 一个sort不香吗,再从2到n-1累加不就行了,最后
h=g;
h=h/(n-2);
printf("%.2f",h);
by HFAKzzy @ 2020-09-05 14:41:13
1.数组小了
2.
by AdventureExtremeX @ 2020-09-05 14:41:39
h=h+g/(n-2);
改成
h=(g*1.0)/(n-2.0);
因为 g 和 n 还有 2 都是 int 的,所以算不出小数
by AdventureExtremeX @ 2020-09-05 14:42:20
@sky同my 推荐阅读《画蛇添足》
by AdventureExtremeX @ 2020-09-05 14:44:36
HFAK正解√
by wusiyuan @ 2020-09-05 14:46:41
@HFAKzzy 我试试
by wusiyuan @ 2020-09-05 14:47:24
@xiaozengXW 好的我试试谢谢
by wusiyuan @ 2020-09-05 14:48:39
@sky同my sort我不会啊 萌新 刚学完二维数
by HFAKzzy @ 2020-09-05 14:50:37
@wusiyuan 没必要 sort 吧,虽然我就是用 sort 的