Advertisement
YavorGrancharov

Average_Grades

Jan 4th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Average_Grades {
  4.     public static void main(String[] args) {
  5.         Scanner console =  new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(console.nextLine());
  8.  
  9.         Map<String, List<Double>> grades = new LinkedHashMap<>();
  10.         for (int i = 0; i < n; i++) {
  11.             String line = console.nextLine();
  12.             String[] tokens = line.split("\\s+");
  13.             String name = tokens[0];
  14.             String[] asDigits = tokens[1].split("\\s+");
  15.  
  16.             List<Double> converted = new ArrayList<>(asDigits.length);
  17.  
  18.             for (int j = 0; j < asDigits.length; j++) {
  19.                 converted.add(Double.parseDouble(asDigits[j]));
  20.             }
  21.  
  22.             if (!grades.containsKey(name)) {
  23.                 grades.put(name, new ArrayList<>());
  24.             }
  25.             grades.put(name, converted);
  26.         }
  27.         for (Map.Entry<String, List<Double>> entry : grades.entrySet()) {
  28.             System.out.println(entry.getKey() + " -> " + entry.getValue());
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement