zaobei @ 2023-07-28 11:03:37
#include<iostream>
#include <iomanip>
using namespace std;
int main(){
int n;
cin>>n;
double a[n],MAX=0,MIN=a[0],sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>MAX){
MAX=a[i];
}
if(a[i]<MIN){
MIN=a[i];
}
sum+=a[i];
}
sum=sum-MAX-MIN;
cout<<setprecision(3)<<sum/(n-2);
return 0;
}
by zaobei @ 2023-07-28 11:04:49
第一个过不了,后面的过了
by hzoi_Shadow @ 2023-07-28 11:09:35
@zaobei 数组最好不要定义在main里面,现在你的MAX和MIN可能会越界
by exCat @ 2023-07-28 11:13:14
min的初值有问题。
by exCat @ 2023-07-28 11:15:43
赋初值时,
ac代码
#include<iostream>
#include <iomanip>
using namespace std;
int n;
double a[1010],MAX=0,MIN=100010,sum=0;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>MAX){
MAX=a[i];
}
if(a[i]<MIN){
MIN=a[i];
}
sum+=a[i];
}
sum=sum-MAX-MIN;
cout<<setprecision(3)<<sum/(n-2);
return 0;
}
by zaobei @ 2023-07-28 11:19:10
OK,学到了,感谢!!!