Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner sc=new Scanner(System.in);
- HashMap<String, List<String>> coursesMap=new HashMap<>();
- String strInput="";
- while(!(strInput=sc.nextLine()).equals("end")){
- String[] inpArr=strInput.split(" : ");
- String course=inpArr[0];
- String name=inpArr[1];
- coursesMap.putIfAbsent(course,new ArrayList<>());
- List<String> courseMembers=coursesMap.get(course);
- if (courseMembers.indexOf(name)<0){
- courseMembers.add(name);
- }
- }
- coursesMap.entrySet().stream()
- .sorted((e1,e2)->e2.getValue().size() - e1.getValue().size())
- .forEach(e->{
- System.out.printf("%s: %d%n",e.getKey(),e.getValue().size());
- e.getValue().stream()
- .sorted()
- .forEach(name-> System.out.printf("-- %s%n",name));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement