#C14484. Merge and Intersect Lists
Merge and Intersect Lists
Merge and Intersect Lists
You are given two lists of integers. Your task is to compute two results:
- The union of the two lists, which is the set of all distinct elements present in either list. That is, \(A \cup B\).
- The intersection of the two lists, which is the set of all distinct elements present in both lists. That is, \(A \cap B\).
The results must be printed in ascending order on two separate lines. The first line should contain the union and the second line should contain the intersection. If any resulting list is empty, print an empty line for that case.
Note: The input will be provided via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line contains zero or more integers separated by spaces representing the first list.
- The second line contains zero or more integers separated by spaces representing the second list.
If a list is empty, the corresponding line will be empty.
outputFormat
The output should contain two lines:
- The first line is the union of the two lists (all distinct integers) printed in ascending order, separated by spaces.
- The second line is the intersection of the two lists (common distinct integers) printed in ascending order, separated by spaces. If there are no common elements, print an empty line.
1 3 4 6 7 9
1 2 4 5 9 10
1 2 3 4 5 6 7 9 10
1 4 9
</p>