sweet_520 @ 2024-10-15 08:40:52
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
double arr[301] = {0};
double sum1 = 0;
double av1;
int m1=-1, m2=-1;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum1 = sum1 + arr[i];
}
av1 = sum1 / n;
double max = 0;
double min = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
m1 = i;
}
}
for (int i = 0; i < n; i++)
{
if (arr[i] <min)
{
min = arr[i];
m2 = i;
}
}
double cha=0;
for (int i = 0; i < n; i++)
{
if (i!=m1&&i!=m2)
{
if (fabs(arr[i] - av1) > cha)
{
cha = fabs(arr[i] - av1);
}
}
}
cout << fixed << setprecision(2) << av1;
cout << " " << fixed << setprecision(2) << cha << endl;
return 0;
}
by liupinli2012_mini @ 2024-10-15 08:45:35
#include<bits/stdc++.h>
using namespace std;
double a[305],sum=0;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i],sum+=a[i];
sort(a+1,a+1+n);
sum-=a[1]+a[n];
sum/=(n-2);
cout<<fixed<<setprecision(2)<<sum<<" "<<max(abs(sum-a[2]),abs(sum-a[n-1]));
return 0;
}
by liupinli2012_mini @ 2024-10-15 08:45:56
关注我的大号Sixchestnuts
by liupinli2012_mini @ 2024-10-15 08:52:19
@sweet_520
by liupinli2012_mini @ 2024-10-15 09:07:37
@sweet_520 在?
by Melo_DDD @ 2024-10-15 09:11:01
@liupinli2012_mini 人家要的是解决问题,不是让你给一份 AC 代码
by sweet_520 @ 2024-10-15 09:14:38
@liupinli2012_mini 我在,能帮我看看为什么我的代码只有30分吗?谢谢了
by tterl @ 2024-10-15 09:14:40
现在求关注都这种程度了吗
by Melo_DDD @ 2024-10-15 09:18:27
@sweet_520 你的平均值求的是所有的平均值,题目里说的是求删了最大最小值之后的平均值
by liupinli2012_mini @ 2024-10-15 09:21:11
我知道了,你的min在求最小值时没有把下标标为0而是-1,就会导致如果最小值就是arr[0]就不会跟新下标了
by liupinli2012_mini @ 2024-10-15 09:21:41
把m2的初始值设为0 @sweet_520