#C7036. Capture Trees
Capture Trees
Capture Trees
You are given a row of trees represented by a string where each character denotes a type of tree. Your task is to find the lexicographically smallest substring that contains all distinct characters from the input string. In other words, for each test case, extract all unique characters from the string, sort them in increasing (lexicographical) order, and output the resulting string.
The problem can be formulated as follows:
Let \( s \) be a string representing a row of trees. Define \( U(s) \) as the set of distinct characters in \( s \). The answer for each test case is the string obtained by concatenating the elements of \( U(s) \) after sorting them in ascending order.
Input format: The first line contains an integer \( T \) representing the number of test cases. Each of the following \( T \) lines contains a single non-empty string \( s \) of lowercase letters.
Output format: For each test case, output the lexicographically smallest string (on a new line) that is formed by the sorted unique characters of the input string.
Make sure your solution reads from stdin
and writes to stdout
.
inputFormat
The input starts with an integer \( T \) (\(1 \leq T \leq 1000\)), the number of test cases. The next \( T \) lines each contain a non-empty string of lowercase letters representing a row of trees.
Example:
3 oxoxoxox efedcba abcdefgh
outputFormat
For each test case, output a line containing the lexicographically smallest string of unique characters from the given string.
Example:
ox abcdef abcdefgh## sample
3
oxoxoxox
efedcba
abcdefgh
ox
abcdef
abcdefgh
</p>