imbigsb @ 2022-05-19 12:42:31
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,minn,maxn;
cin>>n;
double ans=0;
int a[1200]={0};//已经比题目给的范围多了200,应该够了.
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]<a[i-1]){
minn=a[i];
}
if(a[i]>a[i-1]){
maxn=a[i];
}
}
for(int i=0;i<=n;i++){
ans=ans+a[i];
}
ans=ans-maxn-minn;
ans=ans/(n-2);
printf("%.2f",ans);
return 0;
}
by ConanOI_Official @ 2022-05-19 12:46:31
5
10 1 10 9 10
by Starw @ 2022-05-19 12:49:46
我不理解。
您为什么是这样求最值的?
if(a[i]<a[i-1]){
minn=a[i];
}
if(a[i]>a[i-1]){
maxn=a[i];
}
不该这样吗?
if(a[i]<minn){
minn=a[i];
}
if(a[i]>maxn){
maxn=a[i];
}
by Starw @ 2022-05-19 12:50:05
@2024WP10
by imbigsb @ 2022-05-19 12:50:53
@dz3284 emmm 让我试试
by Starw @ 2022-05-19 12:55:55
@2024WP10 还有您 minn,maxn 没设初值
by imbigsb @ 2022-05-19 13:05:38
@dz3284 谢谢您的耐心指导,我在您的帮助下终于过了!
by imbigsb @ 2022-05-19 13:06:36
@ConanOI_Official 谢谢您提供的帮助和测试数据,您为我提供了很大帮助,我终于过了,谢谢!
by nikodo @ 2022-07-08 21:40:02
#include<iostream>
#include<iomanip>
using namespace std;
int n,a[1000],big=0,small=11;
int f=0;
float s;
void dafen(){
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>big)
big=a[i];
if(a[i]<small)
small=a[i];
f+=a[i];
}
f=f-big-small;
s=(float)f/(n-2);
cout<<fixed<<setprecision(2)<<s;
}
int main(){
dafen();
return 0;
}