#C3696. Unique Bracketed Substrings Concatenation
Unique Bracketed Substrings Concatenation
Unique Bracketed Substrings Concatenation
Given an input string containing substrings enclosed in square brackets, your task is to extract each substring and concatenate them into one string. However, if a substring appears more than once, only the first occurrence is considered. The order of substrings in the output must be the same as their first appearance in the input.
For example, given the string [abc][def][ghi][abc][ghi]
, the output should be abcdefghi
because although abc
and ghi
appear twice, only their first appearance is used.
The extraction process can be described by the following formula in \( \LaTeX \):
\[ \text{Output} = \bigoplus_{i=1}^{k} s_i, \quad \text{if} \quad s_i \notin \{s_1, s_2, \dots, s_{i-1}\} \]Here, \( s_i \) represents the substring extracted from an occurrence of \( [s_i] \) in the input, and \( \bigoplus \) denotes the concatenation operation.
inputFormat
The input consists of a single line containing a string. This string is composed of substrings enclosed within '[' and ']'. The substrings may be empty.
outputFormat
Output a single line string that is the concatenation of unique substrings (in order of their first appearance) extracted from the input.
## sample[abc]
abc
</p>