#C13058. Find Common Elements in Two Arrays

    ID: 42554 Type: Default 1000ms 256MiB

Find Common Elements in Two Arrays

Find Common Elements in Two Arrays

Given two arrays of integers provided on two separate lines of input, write a program that computes the common elements between the two arrays. The program should remove duplicate values and output the result as a sorted sequence (in ascending order).

In mathematical terms, if the two arrays represent sets (A) and (B), you are to compute (A \cap B) and output the sorted elements of the intersection.

inputFormat

The input consists of two lines:

  • The first line contains a space-separated list of integers representing the first array.
  • The second line contains a space-separated list of integers representing the second array.

Note: Either or both arrays may be empty.

outputFormat

Output a single line containing the common integers (after removing duplicates) sorted in ascending order and separated by a single space. If there are no common elements, output an empty line.## sample

4 9 5 4 8
9 4 9 8 4
4 8 9