Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package june22;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- import javax.xml.crypto.dsig.keyinfo.KeyValue;
- public class ExamResults {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- for (int i = 0; i < 3; i++) {
- input.nextLine();
- }
- TreeMap<Integer, TreeMap<String, Double>> mapmap = new TreeMap<>();
- while (true) {
- String nextStudent = input.nextLine();
- if (nextStudent.contains("-")) {
- break;
- }
- String[] container = nextStudent.split("[^a-zA-Z0-9.]+");
- String name = container[1] + " " + container[2];
- int score = Integer.parseInt(container[3]);
- double mark = Double.parseDouble(container[4]);
- double tempValue = 0.0;
- if (mapmap.get(score) == null) {
- mapmap.put(score, new TreeMap<>());
- mapmap.get(score).put(name, mark);
- }
- else {
- if (mapmap.get(score).get(name) == null) {
- mapmap.get(score).put(name, mark);
- }
- else {
- tempValue = mapmap.get(score).get(name) + mark;
- mapmap.get(score).put(name, tempValue);
- }
- }
- }
- for (Map.Entry<Integer, TreeMap<String, Double>> p : mapmap.entrySet()) {
- System.out.print(p.getKey() + " -> ");
- Map<String, Double> temp = p.getValue();
- String output = temp.toString().replaceAll("[(=0-9.0-2+)]", "").replace('{', '[').replace('}', ']');
- System.out.print(output);
- double sum = 0.0;
- int size = 0;
- for (Map.Entry<String, Double> k : temp.entrySet()) {
- double current = k.getValue();
- sum += current;
- size++;
- }
- System.out.printf("; avg=%.2f\n", sum / size);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement