#C12628. Remove Duplicates While Preserving Order
Remove Duplicates While Preserving Order
Remove Duplicates While Preserving Order
You are given a list of integers. Your task is to remove duplicate elements while preserving the order of their first appearance.
For example, if the input list is [1, 2, 2, 3, 4, 4, 4, 5], then the output should be [1, 2, 3, 4, 5].
This problem tests your ability to process input from stdin and output the result to stdout while ensuring that the order of elements is maintained after removing duplicates.
The solution should work for any list of integers including the empty list.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains an integer \(N\), which is the number of elements in the list.
- The second line contains \(N\) space-separated integers.
If \(N = 0\), the second line may be empty.
outputFormat
Print the list of integers after removing duplicates, preserving their original order. The integers should be printed in a single line separated by a space.
## sample8
1 2 2 3 4 4 4 5
1 2 3 4 5