xiaosujiayou @ 2024-03-05 21:37:27
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
double a[10000],b[10000],maxn=-1,minn=9999999,sum1=0,sum2=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
minn=min(minn,a[i]);}
for(int i=1;i<=n;i++){
if(a[i]!=maxn||a[i]!=minn)
sum1+=a[i];}
cout<<fixed<<setprecision(2)<<sum1/(n-2)<<" ";
for(int i=1;i<=n;i++){
if(a[i]!=maxn&&a[i]!=minn)
b[i]=a[i]-sum1/(n-2);
sum2+=b[i];}
cout<<fixed<<setprecision(2)<<sum2;
return 0;
}
by xutengyuan @ 2024-03-05 21:40:18
@xiaosujiayou 这马蜂……
by xiaosujiayou @ 2024-03-05 21:49:07
@xutengyuan 什么?
by xutengyuan @ 2024-03-05 21:49:43
@xiaosujiayou 咋都不缩进?
by Little_in_vain @ 2024-04-27 16:49:56
......
by Little_in_vain @ 2024-04-27 16:53:44
不用max和min sort(a + 1, a + 1 + n); for (int i = 2; i < n; i++) { sum += a[i]; } double av = sum / (double)(n - 2); 就可以啦 看下代码:
#include<bits/stdc++.h>
using namespace std;
double a[1000005];
int main()
{
int n,cnt=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a + 1, a + 1 + n);
double sum = 0;
for (int i = 2; i < n; i++)
{
sum += a[i];
}
double av = sum / (double)(n - 2);
double mx = -1;
for (int i = 2; i < n; i++)
{
mx = max(mx, fabs(a[i] - av));
}
printf("%.2f %.2f", av, mx);
}
关个注吧 QWQ