chenyyegg @ 2023-11-19 17:03:34
#include<bits/stdc++.h>
using namespace std;
double a[305],big,small=1000,ave,dif,sum;
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int j=1;j<=n;j++)
{sum+=a[j];
if(a[j]>big)big=a[j];
if(a[j]<small)small=a[j];}
sum-=(big+small);
ave=sum/(n-2);
for(int k=1;k<=n;k++)
{if(a[k]==big||a[k]==small)continue;
if(fabs(a[k]-ave)>dif)dif=fabs(a[k]-ave);}
printf("%.2f %.2f",ave,dif);
return 0;
}
悬赏一个关注给大佬
by 120229xhj @ 2023-11-23 15:10:58
#include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
// 防止越界
double arr[310];
double maxx = -1,minn = 10000;
// 标记变量
int maxIndex = 0,minIndex = 0;
// 初始化和 计算平均值
double sum = 0;
for(int i = 0;i<n;i++){
// 录入数据
scanf("%lf",&arr[i]);
sum+=arr[i];
// 更新最值
maxx = maxx>arr[i]?maxx:arr[i];
// 更新索引
maxIndex = maxx>arr[i]?maxIndex:i;
minn = minn<arr[i]?minn:arr[i];
minIndex = minn<arr[i]?minIndex:i;
}
// 减去最值
double average = (sum-minn-maxx)/(n-2);
// 找到最大误差
double dis = -1;
for(int i = 0;i<n;i++){
if(i!=maxIndex&&i!=minIndex){
if(dis<fabs(arr[i]-average)) dis = fabs(arr[i]-average);
}
}
printf("%.2f %.2f",average,dis);
return 0;
by chenyyegg @ 2023-11-26 09:42:51
@120229xhj 谢大佬帮助,已关注
by 120229xhj @ 2023-11-29 19:20:01
没事(我才一个新手),技术不高,只是刚好会,我考到17级
by 120229xhj @ 2023-11-29 19:21:17
弱弱地问一句:能加入我的团队吗?