Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company.Lists;
- import java.util.*;
- public class UnunionLists {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- List<String> primalList = new ArrayList<>(Arrays.asList(scan.nextLine().split(" ")));
- int n = Integer.parseInt(scan.nextLine());
- for (int i = 0; i < n; i++) {
- List<String> currentList = new ArrayList<>(Arrays.asList(scan.nextLine().split(" ")));
- for (int j = currentList.size() - 1; j >= 0; j--) {
- if (!primalList.contains(currentList.get(j))) {
- primalList.add(currentList.get(j));
- } else {
- primalList.removeAll(Collections.singleton(currentList.get(j)));
- }
- }
- }
- Collections.sort(primalList);
- for (String num : primalList) {
- System.out.print(num + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement