Advertisement
Sim0o0na

Untitled

Jun 29th, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package com.company.Lists;
  2.  
  3. import java.util.*;
  4.  
  5. public class UnunionLists {
  6. public static void main(String[] args) {
  7.  
  8. Scanner scan = new Scanner(System.in);
  9.  
  10. List<String> primalList = new ArrayList<>(Arrays.asList(scan.nextLine().split(" ")));
  11.  
  12. int n = Integer.parseInt(scan.nextLine());
  13.  
  14. for (int i = 0; i < n; i++) {
  15.  
  16. List<String> currentList = new ArrayList<>(Arrays.asList(scan.nextLine().split(" ")));
  17.  
  18. for (int j = currentList.size() - 1; j >= 0; j--) {
  19. if (!primalList.contains(currentList.get(j))) {
  20. primalList.add(currentList.get(j));
  21. } else {
  22. primalList.removeAll(Collections.singleton(currentList.get(j)));
  23. }
  24. }
  25. }
  26.  
  27. Collections.sort(primalList);
  28.  
  29. for (String num : primalList) {
  30. System.out.print(num + " ");
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement