Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Average_Grades {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- int n = Integer.parseInt(console.nextLine());
- Map<String, List<Double>> grades = new LinkedHashMap<>();
- for (int i = 0; i < n; i++) {
- String line = console.nextLine();
- String[] tokens = line.split("\\s+");
- String name = tokens[0];
- String[] asDigits = tokens[1].split("\\s+");
- List<Double> converted = new ArrayList<>(asDigits.length);
- for (int j = 0; j < asDigits.length; j++) {
- converted.add(Double.parseDouble(asDigits[j]));
- }
- if (!grades.containsKey(name)) {
- grades.put(name, new ArrayList<>());
- }
- grades.put(name, converted);
- }
- for (Map.Entry<String, List<Double>> entry : grades.entrySet()) {
- System.out.println(entry.getKey() + " -> " + entry.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement