Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package P6Course;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, TreeSet<String>> courses = new LinkedHashMap<>();
- String command;
- while (!"end".equals(command = scanner.nextLine())) {
- String[] data = command.split(" : ");
- String course = data[0];
- String student = data[1];
- courses.putIfAbsent(course, new TreeSet<>());
- courses.get(course).add(student);
- }
- courses
- .entrySet()
- .stream()
- .sorted((a, b) -> Integer.compare(b.getValue().size(), a.getValue().size()))
- .forEach(e -> {
- System.out.println(e.getKey() + ": " + e.getValue().size());
- e.getValue().forEach(u -> System.out.println("-- " + u));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement