123ytq666 @ 2024-03-17 14:33:23
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n;
double tall=0.0,small=1000000000,sum=0.0,cnt=0.0;
bool t1=0,s1=0;
cin>>n;
double a[n];
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>tall)tall=a[i];
if(a[i]<small)small=a[i];
sum+=a[i];
}
sum=sum-tall-small;
sum/=(n-2);
for(int i=0;i<n;i++){
double k;
if(k==tall&&t1==0){
t1=1;
continue;
}
if(k==small&s1==0){
s1=1;
continue;
}
k=a[i]-sum;
if(fabs(k)>cnt)cnt=fabs(k);
}
cout<<fixed<<setprecision(2)<<sum<<" "<<cnt;
return 0;
}
by Eason1218 @ 2024-04-15 21:05:18
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >>n;
float a[1298];
for (int i=1;i<=n;i++){
cin >>a[i];
}
for (int i=1;i<=n;i++){
for (int j=1;j<=n-i;j++)
if (a[j]>a[j+1])
swap(a[j],a[j+1]);
}
float sum=0.00;
for (int i=2;i<n;i++){
sum+=a[i];
}
printf("%.2lf ",sum/=(n-2));
float b[n];
for (int i=2;i<n;i++){
b[i]=abs(a[i]-sum);
}
float ma=0.00;
for (int i=1;i<=n;i++){
if(ma<b[i])
ma=b[i];
}
printf("%.2lf",ma);
return 0;
}
by Eason1218 @ 2024-04-15 21:08:04
可以借鉴(求互关)