-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiveWater.java
More file actions
30 lines (27 loc) · 981 Bytes
/
Copy pathReceiveWater.java
File metadata and controls
30 lines (27 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
import java.util.HashMap; // 引入 HashMap 类
import java.util.Map;
public class ReceiveWater {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<Integer, Integer> Person = new HashMap<Integer, Integer>();
for (int i = 1; i <= n; i++) {
int x = sc.nextInt();
Person.put(i, x);
}
int[] res = Person.entrySet().stream().sorted((a, b) -> a.getValue() - b.getValue()).mapToInt(Map.Entry::getKey)
.toArray();
for (int i = 0; i < n; i++) {
System.out.print(res[i] + " ");
}
System.out.println();
double sum = 0;
for (int i = 0; i < n; i++) {
sum += Person.get(res[i]) * (n - i - 1);
}
double result = sum / n;
String formattedResult = String.format("%.2f", result);
System.out.println(formattedResult);
}
}