#C354. Common Elements Finder
Common Elements Finder
Common Elements Finder
You are given two arrays of integers. Your task is to find the common elements between the two arrays while preserving the order of their first occurrence in the first array.
More formally, given two lists \(a\) and \(b\), you need to output a list \(c\) such that each element in \(c\) appears in both \(a\) and \(b\) and the order in \(c\) is the same as the order in which they first appear in \(a\). Note that even if an element appears multiple times, it should appear only once in the output.
Input Format: The input is read from standard input (stdin) and consists of two lines. The first line represents the array \(a\) and the second line represents the array \(b\). Each line is a series of integers separated by spaces. An empty line represents an empty array.
Output Format: Print the common elements (if any) separated by a single space on a single line. If there are no common elements, print an empty line.
For example, if \(a = [1, 2, 3, 3, 4]\) and \(b = [3, 4, 5, 6]\), the output should be 3 4
.
inputFormat
The input consists of two lines:
- The first line contains space-separated integers representing array \(a\). It can be empty.
- The second line contains space-separated integers representing array \(b\). It can be empty.
outputFormat
Output a single line containing the common elements (if any) in the order of their first occurrence in \(a\), separated by spaces. If there are no common elements, output an empty line.
## sample1 2 3 3 4
3 4 5 6
3 4