Advertisement
Guest User

Untitled

a guest
Jul 13th, 2019
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7. import java.util.TreeMap;
  8.  
  9. public class companyUsers {
  10.  
  11. public static void main(String[] args) {
  12. // TODO Auto-generated method stub
  13. Scanner sc = new Scanner (System.in);
  14. TreeMap<String, ArrayList<String>> companies = new TreeMap<>();
  15. String command = sc.nextLine();
  16.  
  17. while (!command.equals("End")) {
  18. String[] tokens = command.split(" -> ");
  19. String company = tokens[0];
  20. String id = tokens[1];
  21.  
  22. if (!companies.containsKey(company)) {
  23. companies.put(company, new ArrayList<String>());
  24. }
  25. if (companies.containsKey(company) && !companies.get(company).contains(id)) {
  26. companies.get(company).add(id);
  27. }
  28. command = sc.nextLine();
  29. }
  30. for (var entry : companies.entrySet()) {
  31. System.out.println(entry.getKey());
  32. for (String ids : entry.getValue()) {
  33. System.out.println("-- "+ ids);
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement