#C13867. Remove Duplicates from a List
Remove Duplicates from a List
Remove Duplicates from a List
You are given a list of elements, which can be either integers or strings. Your task is to remove duplicate elements from the list while preserving the order of their first appearance.
The program should also support an optional flag that enables case-insensitive duplicate removal for string elements. When the flag is active, two strings that differ only in their letter case (for example, "a" and "A") should be considered identical, but the output should preserve the original case of the first occurrence.
If the input is not a valid list, the program must report an error by printing an error message.
Note: The case-insensitive mode only applies when processing string lists.
inputFormat
The input is provided via standard input (stdin
) with the following format:
- The first line contains a single integer N, which is the number of elements in the list.
- The second line contains N space-separated tokens. Each token represents an element. If a token can be interpreted as an integer, treat it as an integer; otherwise, treat it as a string.
- The third line is optional. If it is present and its value is either
1
ortrue
(case-insensitive), duplicate removal for string elements should be performed in a case-insensitive manner. If this line is absent or its value is0
orfalse
, perform duplicate removal normally.
outputFormat
Output to standard output (stdout
) the list of unique elements, in the order of their first appearance, with each element separated by a single space.
7
1 2 2 3 4 4 5
0
1 2 3 4 5