#K81447. Distinct Unique Character Substrings
Distinct Unique Character Substrings
Distinct Unique Character Substrings
You are given a string S consisting of lowercase alphabetic characters. Your task is to list all the distinct substrings of S that contain exactly one unique character, i.e. the substring is composed of a single repeated character.
For example, if S = "aaabb"
, then the substrings are: "a", "aa", "aaa", "b", "bb".
The answer should be printed in lexicographical order. Note that the lexicographical order here means that for any two strings, the one that is a prefix of the other is considered smaller.
Mathematical formulation:
Given a string S, find the set
\[
U = \{ s[i\ldots j] : 0 \le i \le j < |S|, \; \forall k, i \le k \le j,\ s[k]=c \text{ for some } c \in \{a,\ldots,z\} \}\]
\]
and output the sorted list of substrings in increasing lexicographical order.
inputFormat
The input is read from standard input and consists of a single line containing the string S (1 ≤ |S| ≤ 100).
outputFormat
Output the distinct substrings that contain exactly one unique character, each on a separate line, in lexicographical order.
## sampleaaabb
a
aa
aaa
b
bb
</p>