Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class _06_Courses {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<String>> courseByStudents = new LinkedHashMap<>();
- String input = "";
- while (!"end".equals(input = scanner.nextLine())) {
- String[] line = input.split(" : ");
- courseByStudents.putIfAbsent(line[0], new ArrayList<>());
- courseByStudents.get(line[0]).add(line[1]);
- Collections.sort(courseByStudents.get(line[0]));
- }
- courseByStudents
- .entrySet()
- .stream()
- .sorted((x, y) -> Integer.compare(y.getValue().size(), x.getValue().size()))
- .forEach(entry -> {
- System.out.println(String.format("%s: %d", entry.getKey(), entry.getValue().size()));
- entry.getValue().forEach(e -> {
- System.out.println("-- " + e);
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement