lucy2012 @ 2024-02-07 12:09:50
请大佬指点
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
double a[201],sum=0,sum1=0,max=0,min=10000000,max1,min1;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(max<a[i])
max=a[i],max1=i;
if(min>a[i])
min=a[i],min1=i;
sum+=a[i];
}
sum=sum-min-max;
printf("%.2lf ",sum/(n-2)) ;
for(int i=1;i<=n;i++){
if(i==max1||i==min1)
continue;
if(abs(a[i]-sum/(n-2))>sum1)
sum1=abs(a[i]-sum/(n-2));
}
printf("%.2lf",sum1);
return 0;
}
by lucy2012 @ 2024-02-07 12:10:55
测试点3,4,7,8,10全RE
by wanglexi @ 2024-02-07 12:13:54
2<n\le300
a
数组开小了。
AC 代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
double a[301/*这里*/],sum=0,sum1=0,max=0,min=10000000,max1,min1;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(max<a[i])
max=a[i],max1=i;
if(min>a[i])
min=a[i],min1=i;
sum+=a[i];
}
sum=sum-min-max;
printf("%.2lf ",sum/(n-2)) ;
for(int i=1;i<=n;i++){
if(i==max1||i==min1)
continue;
if(abs(a[i]-sum/(n-2))>sum1)
sum1=abs(a[i]-sum/(n-2));
}
printf("%.2lf",sum1);
return 0;
}
by wanglexi @ 2024-02-07 12:14:50
@lucy2012
by lucy2012 @ 2024-02-07 12:23:21
@wanglexi 谢谢~