#K47987. Merge Unique Problems
Merge Unique Problems
Merge Unique Problems
You are given several test cases. In each test case, you have two lists of problem identifiers. The first list and the second list may contain duplicate problems when considered together, but you need to merge them into a single list where each problem appears only once, preserving the order in which they first appear.
Formally, let \(A\) be the first list and \(B\) be the second list. Define the merged list \(M\) as:
\[ M = \text{unique}(A \Vert B) \quad \text{(preserving the order of first occurrences)} \]Your task is to implement a solution that reads the input from stdin and writes the output to stdout.
inputFormat
The input begins with an integer T
representing the number of test cases. For each test case, there are two consecutive lines:
- The first line starts with an integer
N
followed byN
strings representing the first list of problem names. - The second line starts with an integer
M
followed byM
strings representing the second list of problem names. Note thatM
can be zero.
All tokens are separated by whitespace.
outputFormat
For each test case, output a single line containing the merged list of unique problem names. The problem names should be separated by a single space, and the order must be the same as their first occurrence in the combined input lists.
## sample2
3 hackathon1 problem2 challenge3
4 problem2 challenge3 hackathon1 problem4
5 code1 code2 code3 code4 code5
3 code5 code6 code7
hackathon1 problem2 challenge3 problem4
code1 code2 code3 code4 code5 code6 code7
</p>