Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class _07_StudentAcademy_v_2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Map<String, List<Double>> map = new LinkedHashMap<>();
- for (int i = 0; i < n; i ++) {
- String name = scanner.nextLine();
- double grade = Double.parseDouble(scanner.nextLine());
- map.putIfAbsent(name, new ArrayList<>());
- map.get(name).add(grade);
- }
- Map<String, Double> avg = new LinkedHashMap<>();
- for (String name : map.keySet()) {
- double sum = 0;
- int size = map.get(name).size();
- for (int i = 0; i < size; i++) {
- sum += map.get(name).get(i);
- }
- double average = sum / size;
- if (average >= 4.5) {
- avg.put(name, average);
- }
- }
- avg.entrySet()
- .stream()
- .sorted(Map.Entry.<String, Double>comparingByValue().reversed())
- .forEach(kvp -> System.out.printf("%s -> %.2f%n", kvp.getKey(), kvp.getValue()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement