_1698abc @ 2023-03-08 19:31:08
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
float num=0,pin,cha=0,b=0,c=99999999;
int n;
float a[200] = {0};
cin >> n;
for (int i = 0; i <= n - 1; i++)
{
cin >> a[i];
}
for (int i = 0; i <= n - 1; i++)
{
b = max(b, a[i]);
c = min(c, a[i]);
num += a[i];
}
pin = (num - b - c) / (n - 2);
float p;
for (int j = 0; j <= n - 1; j++)
{
if (a[j] == b || a[j]==c)
{
continue;
}
p = abs(a[j] - pin);
cha = max(cha, p);
}
cout << fixed << setprecision(2) << pin << " " << cha;
}
by WA_sir @ 2023-03-08 19:48:41
@_1698abc
你是 Wrong Answer 罢
by tangguo_yyds @ 2023-03-08 19:55:05
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
double num=0,pin,cha=0,b=0,c=99999999;
int n,x,y;
double a[310] = {0};
cin >> n;
for (int i = 0; i <= n - 1; i++)
{
cin >> a[i];
if(a[i]<c){
c=a[i];
x=i;
}
if(a[i]>b){
b=a[i];
y=i;
}
num += a[i];
}
pin = (num - b - c) / (n - 2);
double p;
for (int j = 0; j <= n - 1; j++)
{
if (j!=x&&j!=y)
{
p = abs(a[j] - pin);
cha = max(cha, p);
}
}
cout << fixed << setprecision(2) << pin << " " << cha;
}
by tangguo_yyds @ 2023-03-08 19:58:54
@_1698abc
数组开小了,而且只去掉一个最大值和最小值,
if (a[j] == b || a[j]==c)
可能去掉不止一个最大值和最小值
而且可以边输入边找最大值和最小值,并加总和
by tangguo_yyds @ 2023-03-08 19:59:37
题目中只要求去掉一个最大值和最小值
by _1698abc @ 2023-03-09 16:13:58
@WA_sir 好的,谢谢
by _1698abc @ 2023-03-09 16:14:24
@tangguo_yyds 感谢感谢