CZH_xixi @ 2024-04-11 15:34:17
#include<bits/stdc++.h>
using namespace std;
double n,a[1005],sum,ma,mi;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
ma=max(ma,a[i]);
mi=min(mi,a[i]);
}
printf("%.2lf",(sum-ma-mi)/(n-2));
}
第一个样例过不去,神犇求助
by 违规用户名1284771 @ 2024-04-11 16:20:33
你可以用cout<<mixed<<setprecision(2); 试试小数位数
by 违规用户名1284771 @ 2024-04-11 16:24:53
试试这个
https://www.luogu.com.cn/paste/ce4mwbev
by 违规用户名1284771 @ 2024-04-11 16:25:17
@2023_1202
by __Function__ @ 2024-04-21 17:28:04
你可以把ma与mi设成极端数据,如ma=8445579834,mi=-2387548(各种都可以)
by LiXiang190208 @ 2024-05-12 12:08:32
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[1000],s=1,j=1000,sum=0;
cin>>n;
for(int i=0;i++;i<n){
cin>>a[i];
sum+=a[i];
}
for(int i=0;i++;i<n){
s = max(s,a[i]);
j = min(j,a[i]);
}
sum = sum-s-j;
cout<<fixed<<setprecision(2)<<sum*1.0/(n-2);
return 0;
}
by anyiming @ 2024-05-22 23:05:18
@LiXiang190208 你的for循环的条件的位置写反了。应该是
for(int i=0; i<n; i++){
cin>>a[i];
sum+=a[i];
}
for(int i=0; i<n; i++){
s = max(s,a[i]);
j = min(j,a[i]);
}
这样应该行了
by LiXiang190208 @ 2024-05-24 20:58:59
@ anyiming
Thank you!!