Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. package P6Course;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. Map<String, TreeSet<String>> courses = new LinkedHashMap<>();
  10.  
  11. String command;
  12.  
  13. while (!"end".equals(command = scanner.nextLine())) {
  14. String[] data = command.split(" : ");
  15. String course = data[0];
  16. String student = data[1];
  17.  
  18. courses.putIfAbsent(course, new TreeSet<>());
  19. courses.get(course).add(student);
  20. }
  21.  
  22. courses
  23. .entrySet()
  24. .stream()
  25. .sorted((a, b) -> Integer.compare(b.getValue().size(), a.getValue().size()))
  26. .forEach(e -> {
  27. System.out.println(e.getKey() + ": " + e.getValue().size());
  28. e.getValue().forEach(u -> System.out.println("-- " + u));
  29. });
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement