#C11927. Unique Elements Extraction
Unique Elements Extraction
Unique Elements Extraction
Given a list of integers, your task is to output the list of unique elements in the order they first appear. The input is provided through standard input (stdin
), and the result should be printed to standard output (stdout
). If the input is not a valid list of integers, you must print null
.
Formally, if the input list is \( a[1 \dots n] \), then the output list contains each element \( a[i] \) only if it has not appeared in any \( a[j] \) for \( j < i \). Handle edge cases such as an empty input or invalid tokens appropriately.
inputFormat
The input is a single line read from stdin
consisting of space-separated tokens. Each token should represent an integer. An empty line corresponds to an empty list. If any token is not a valid integer, the input is considered invalid.
outputFormat
If the input is valid, print the unique integers separated by a single space in the order they first appeared. Otherwise, print null
. The output must be written to stdout
.
4 5 6 4 7 8 6 9
4 5 6 7 8 9