Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class Courses {
- public static void main(String[] args) throws IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
- Map<String, List<String>> courses = new LinkedHashMap<>();
- String command;
- while (!"end".equals(command = read.readLine())) {
- String[] info = command.split(" : ");
- courses.putIfAbsent(info[0], new ArrayList<>());
- courses.get(info[0]).add(info[1]);
- }
- courses.entrySet().stream().sorted((course, num) -> Integer.compare(num.getValue().size(), course.getValue().size())).forEach(entry -> {
- System.out.println(String.format("%s: %d", entry.getKey(), entry.getValue().size()));
- Collections.sort(entry.getValue());
- entry.getValue().forEach(name -> System.out.println("-- " + name));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement