Advertisement
psi_mmobile

Untitled

Dec 3rd, 2022
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.*;
  2. public class MyClass {
  3.     public static void main(String args[]) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         Map<String, List<String>> bigMap = new LinkedHashMap<String,List<String>>();
  6.         String nextLine = scanner.nextLine();
  7.         while(true) {
  8.             if(nextLine.equals("end")) {
  9.                 for (Map.Entry<String, List<String>> set : bigMap.entrySet())
  10.                 {
  11.                     System.out.println(set.getKey().trim() + ": " + set.getValue().size());
  12.                     printList(set.getValue());
  13.                 }
  14.                 break;
  15.             } else {
  16.                 String[] arrOfStr = nextLine.split(":");
  17.                 if(!bigMap.containsKey(arrOfStr[0])) {
  18.                     List<String> studentBufferList = new ArrayList<String>();
  19.                     studentBufferList.add(arrOfStr[1]);
  20.                     bigMap.put(arrOfStr[0], studentBufferList);
  21.                 } else {
  22.                     List<String> courseStudents = bigMap.get(arrOfStr[0]);
  23.                     courseStudents.add(arrOfStr[1]);
  24.                     bigMap.put(arrOfStr[0], courseStudents);
  25.                 }
  26.             }
  27.             nextLine = scanner.nextLine();
  28.         }
  29.     }
  30.     public static void printList(List<String> list) {
  31.         for (String student: list) {
  32.             System.out.printf("-- %s\n", student);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement