Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- TreeMap<String, List<Double>> studentWithGrades = new TreeMap<>();
- for (int i = 0; i < n; i++) {
- String[] input = scanner.nextLine().split(" ");
- String name = input[0];
- double grade = Double.parseDouble(input[1]);
- if (!studentWithGrades.containsKey(name)) {
- studentWithGrades.put(name, new ArrayList<>());
- studentWithGrades.get(name).add(grade);
- } else {
- studentWithGrades.get(name).add(grade);
- }
- }
- for (Map.Entry<String, List<Double>> entry : studentWithGrades.entrySet()) {
- String studentName = entry.getKey();
- List<Double> grades = entry.getValue();
- double average = grades.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
- // String gradesAsString = "";
- // for (int i = 0; i < grades.size(); i++) {
- //
- // gradesAsString += grades.get(i) + " ";
- // }
- //System.out.print(gradesAsString);
- System.out.printf("%s -> ", studentName);
- for (Double grade : grades) {
- System.out.print(String.format("%.2f ", grade));
- }
- System.out.printf("(avg: %.2f)%n", average);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement