YgtVictor @ 2024-02-18 11:44:36
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
int main() {
int i;
double s, b, c, d, e, f, g, h, n;
double a[305] ;
b = c = d = e = f = g = h = s = 0;
scanf("%lf", &n);
scanf("%lf", &a[0]);
b = a[0];
c = a[0];
s = a[0];
for (i = 1; i < n; i++) {
scanf("%lf", &a[i]);
if (a[i] <= b) {
d = b;
b = a[i];
}
if (a[i] >= c) {
e = c;
c = a[i];
}
s = s + a[i];
}
s = s - b - c;
s = s / (n - 2);
f = fabs(d - s);
g = fabs(e - s);
if (g > f) {
h = g;
} else {
h = f;
}
printf("%.2lf %.2lf", s, h);
return 0;
}
by _Chjich_ @ 2024-02-23 11:46:52
@YgtVictor 我太蒟蒻了,你看看这个吧(求关QAQ
#include <bits/stdc++.h>
using namespace std;
int n;
double a[10000], s = 0, x;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s += a[i];
}
sort(a + 1, a + n + 1);
s -= (a[1] + a[n]);
s /= (n - 2);
if (s - a[2] <= a[n - 1] - s)
x = a[n - 1] - s;
else
x = s - a[2];
printf("%.2f %.2f", s, x);
}