Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MyClass {
- public static void main(String args[]) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<String>> bigMap = new LinkedHashMap<String,List<String>>();
- String nextLine = scanner.nextLine();
- while(true) {
- if(nextLine.equals("end")) {
- for (Map.Entry<String, List<String>> set : bigMap.entrySet())
- {
- System.out.println(set.getKey().trim() + ": " + set.getValue().size());
- printList(set.getValue());
- }
- break;
- } else {
- String[] arrOfStr = nextLine.split(":");
- if(!bigMap.containsKey(arrOfStr[0])) {
- List<String> studentBufferList = new ArrayList<String>();
- studentBufferList.add(arrOfStr[1]);
- bigMap.put(arrOfStr[0], studentBufferList);
- } else {
- List<String> courseStudents = bigMap.get(arrOfStr[0]);
- courseStudents.add(arrOfStr[1]);
- bigMap.put(arrOfStr[0], courseStudents);
- }
- }
- nextLine = scanner.nextLine();
- }
- }
- public static void printList(List<String> list) {
- for (String student: list) {
- System.out.printf("-- %s\n", student);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement