chenjunye0131 @ 2024-12-25 16:54:29
#include<iostream>
using namespace std;
double a[333],b[333],sum=1;
int main()
{
int n,s;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int max=a[1];
int min=a[1];
for(int i=2;i<=n;i++)
if(a[i]>max)
{
max=a[i];
s=i;
}
for(int i=s;i<=n;i++) a[i]=a[i+1];
for(int i=2;i<=n-1;i++)
if(a[i]<min)
{
min=a[i];
s=i;
}
for(int i=s;i<=n;i++) a[i]=a[i+1];
n=n-2;
for(int i=1;i<=n;i++) sum=sum+a[i];
sum=sum*1.0/n*1.0;
for(int i=1;i<=n;i++)
{
if(a[i]>sum) b[i]=a[i]-sum;
else b[i]=sum-a[i];
}
double m=b[1];
for(int i=2;i<=n;i++)
if(b[i]>m) m=b[i];
printf("%.2f %.2f",sum,m);
return 0;
}
by Diary_Of_Young @ 2024-12-25 17:02:18
#include<bits/stdc++.h>
using namespace std;
double a[101001] , sum , cnt;
int n;
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i] ;
sort(a + 1 , a + n + 1);
for(int i = 2 ; i < n ; i ++) sum += a[i];
sum = 1.0 * sum / (n - 2);
for(int i = 2 ; i < n ; i ++) cnt = max(cnt , fabs(sum - 1.0 * a[i]));
printf("%.2lf %.2lf " , sum , cnt);
return 0;
}
by chenjunye0131 @ 2024-12-25 21:23:53
@Diary_Of_Young 已A壶关