remote87

SoftUni Student Academy

Jul 27th, 2021
915
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Comparator;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.Map.Entry;
  10. import java.util.Scanner;
  11.  
  12. public class Main {
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner sc = new Scanner(System.in);
  16.         int n = Integer.parseInt(sc.nextLine());
  17.         Map<String, List<Double>> grades = new HashMap<>();
  18.  
  19.         while (n != 0) {
  20.             String name = sc.nextLine();
  21.             double grade = Double.parseDouble(sc.nextLine());
  22.  
  23.             if (grades.containsKey(name)) {
  24.                 grades.get(name).add(grade);
  25.             } else {
  26.                 grades.put(name, new ArrayList<>(Arrays.asList(grade)));
  27.             }
  28.             n--;
  29.         }
  30.  
  31.         grades.entrySet().stream().sorted(Entry.<String, List<Double>>comparingByValue((v1, v2) ->
  32.             Double.compare(v2.stream().mapToDouble(Double::doubleValue).summaryStatistics().getAverage(),
  33.                 v1.stream().mapToDouble(Double::doubleValue).summaryStatistics().getAverage()))
  34.         ).filter((k) -> k.getValue().stream().mapToDouble(Double::doubleValue).summaryStatistics().getAverage() >= 4.5)
  35.         .forEachOrdered(p -> {
  36.             System.out.printf("%s -> %.2f%n", p.getKey(), p.getValue().stream().mapToDouble(Double::doubleValue)
  37.             .summaryStatistics().getAverage());
  38.         });
  39.     }
  40. }
RAW Paste Data