Lanzy @ 2022-11-02 21:17:07
#include <stdio.h>
#include <math.h>
double MAX(double a,double b) {double max1; max1=a;if(b>a)max1=b;return max1;}
int main()
{
int n;
scanf("%d",&n);
double a[301]={0};
int i,j;
double sum=0;
double max=-10000000,min=99999999;
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i]);
if(a[i]>max) max=a[i];
if(a[i]<min) min=a[i];
sum+=a[i];
}
sum-=max+min;
double ave=sum/(n-2);
int n1=0,n2=0;
for(i=1;i<=n;i++)
{
if(a[i]==max)
{
n1++;
a[i]=-10000000;
}
if(a[i]==min)
{
n2++;
a[i]=-10000000;
}
}
double wu=0;
for(i=1;i<=n;i++)
{
if(n1>1&&n2<=1&&a[i]!=-10000000)
{
wu=MAX(fabs(ave-max),fabs(ave-a[i]));
}
else if(n1<=1&&n2>1&&a[i]!=-10000000){
wu=MAX(fabs(ave-min),fabs(ave-a[i]));
}
else if(n1>1&&n2>1)
{
wu=MAX(fabs(ave-max),fabs(ave-min));
}
else if (fabs(a[i]-ave)>wu&&a[i]!=-10000000) {
wu=fabs(a[i]-ave);}
}
printf("%.2lf %.2lf",ave,wu);
return 0;
}
by cmz9690 @ 2022-11-02 22:02:26
@Lance_yszc 只会去除一个标本
by Lanzy @ 2022-11-02 22:07:39
@cmz9690 什么意思详细点..
by cmz9690 @ 2022-11-02 22:15:08
for(i=1;i<=n;i++)
{
if(a[i]==max)
{
n1++;
a[i]=-10000000;
}
if(a[i]==min)
{
n2++;
a[i]=-10000000;
}
}
这一段里,您把所有最大和最小的都标记了,题目要求是最大和最小都只去除一个
by cmz9690 @ 2022-11-02 22:15:19
@Lance_yszc
by Lanzy @ 2022-11-03 12:45:40
@cmz9690 这请你仔细看下我后面的讨论,我分了情况讨论到了这个问题..还特地举了许多极端情况验证
by cmz9690 @ 2022-11-03 18:49:29
@Lance_yszc 这样不麻烦吗?排个序不就好了
by Lanzy @ 2022-11-03 18:56:13
什么意思?怎么弄?为啥。那我这个问题出在哪?