2 条题解
-
0
import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); final DecimalFormat df = new DecimalFormat("0.00"); final int sample = scanner.nextInt(); final List<Double> values = new ArrayList<>(); for (int i = 0; i < sample; i++) { double value = scanner.nextDouble(); values.add(value); } Collections.sort(values); values.remove(0); values.remove(values.size() - 1); double average = 0; for (double value : values) { average += value; } average /= (sample - 2); double maximum = 0; for (double value : values) { double result = Math.abs(value - average); if (result < maximum) continue; maximum = result; } System.out.println(df.format(average) + " " + df.format(maximum)); } }
- 1
信息
- ID
- 115
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 3508
- 已通过
- 210
- 上传者