ljj2378746028 @ 2023-10-15 12:23:50
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int x = 0, y = 0;
double arr[] = new double[520];
double sum = 0, max = 0, min = 99999999;//定义总数,最大,最小
for(int i = 1; i <= n; i++) {
arr[i] = input.nextDouble();
if(max < arr[i]) {
max = arr[i];
x = i;
}
if(min > arr[i]) {
min = arr[i];
y = i;
}
sum = sum + arr[i];
}
double ave = (sum - max - min) / (n - 2) * 1.0;
double max_e = 0;
for(int i = 1; i <= n; i++) {
if(x != i && y != i) {
double temp = Math.abs(arr[i] - ave);
if(max_e < temp) max_e = temp;
}
}
// System.out.printf("%.2f ", ave);
System.out.printf("%.2f %.2f", ave, max_e);
}
}
//这个部分是成功的
for(int i = 1; i <= n; i++) {
if(x != i && y != i) {
double temp = Math.abs(arr[i] - ave);
if(max_e < temp) max_e = temp;
}
}
//这个部分是失败的
for(int i = 1; i <= n; i++) {
if(arr[i] != max && arr[i] != min) {
double temp = Math.abs(arr[i] - ave);
if(max_e < temp) max_e = temp;
}
}
by Huangziyu2022 @ 2023-10-15 17:29:54
max当作变量用?
by ljj2378746028 @ 2023-10-29 21:59:38
@Huangziyu2022 你就说这样写能不能跑出结果来
by Huangziyu2022 @ 2023-10-30 22:33:10
@ljj2378746028 应该不行的,蒟蒻表示也不知道