#C9037. Remove Duplicates while Maintaining Order
Remove Duplicates while Maintaining Order
Remove Duplicates while Maintaining Order
Given a sequence of integers provided in a single line (with each integer separated by a space), remove all duplicate values while preserving the order of their first appearance.
The task is to maintain the original order of the numbers, i.e., for every integer, only the first occurrence should be kept in the output.
This problem can be mathematically described as follows: Given a sequence \(a_1, a_2, \dots, a_n\), produce a sequence \(b_1, b_2, \dots, b_k\) such that:
\(\{ b_1, b_2, \dots, b_k \} \subseteq \{ a_1, a_2, \dots, a_n \}\) and for every \(b_i\), it is the first occurrence of that number in the original sequence.
inputFormat
The input is provided via standard input (stdin) as a single line containing zero or more integers separated by spaces.
Example: 4 5 6 4 5 7 8
outputFormat
Output the resulting list of integers after duplicates have been removed, preserving the order of their first appearance, as a single line via standard output (stdout). The integers should be separated by a single space. If there are no integers in the input, output an empty line.
Example output: 4 5 6 7 8
4 5 6 4 5 7 8
4 5 6 7 8