Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Courses {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Map<String, List<String>> usersList = new LinkedHashMap<>();
- String input = sc.nextLine();
- while (!input.toLowerCase().equals("end")) {
- String[] tokens = input.split("\\s:\\s");
- String courseName = tokens[0];
- String user = tokens[1];
- int counter = 0;
- if (usersList.containsKey(courseName)) {
- usersList.get(courseName).add(user);
- } else {
- usersList.put(courseName, new ArrayList<>());
- usersList.get(courseName).add(user);
- }
- input = sc.nextLine();
- }
- usersList.entrySet().stream().sorted((e1, e2) -> Integer.compare(e2.getValue().size(), e1.getValue().size()))
- .forEach(e -> {
- System.out.println(String.format("%s: %d", e.getKey(), e.getValue().size()));
- Collections.sort(e.getValue());
- e.getValue().forEach(a -> System.out.println("-- " + a));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement