Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Courses {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<String>> courses = new LinkedHashMap<>();
- String command = scanner.nextLine();
- while (!command.equals("end")) {
- String[] info = command.split(" : ");
- courses.putIfAbsent(info[0], new ArrayList<>());
- courses.get(info[0]).add(info[1]);
- command = scanner.nextLine();
- }
- 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