-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExamScore.java
44 lines (35 loc) · 1.36 KB
/
ExamScore.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
import java.util.TreeMap;
public class ExamScore {
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
scanner.nextLine();
scanner.nextLine();
scanner.nextLine();
TreeMap<Integer, TreeMap<String, Double>> container = new TreeMap<>();
while (true) {
String[] input = scanner.nextLine().split("\\s*\\|\\s*");
if (input.length < 4) {
break;
}
String name = input[1];
int score = Integer.parseInt(input[2]);
double grade = Double.parseDouble(input[3]);
if (!container.containsKey(score)) {
container.put(score, new TreeMap<>());
}
container.get(score).put(name, grade);
}
for (Integer score : container.keySet()) {
System.out.print(score + " -> ");
System.out.print(container.get(score).keySet() + "; ");
double gradesSum = 0;
for (double grade : container.get(score).values()) {
gradesSum += grade;
}
double averageGrade = gradesSum / container.get(score).values().size();
System.out.println(String.format("avg=%.2f", averageGrade));
}
}
}