#K94967. Counting Distinct Substrings
Counting Distinct Substrings
Counting Distinct Substrings
You are given a string s. Your task is to count the number of distinct substrings present in s. A substring is defined as a contiguous sequence of characters within the string. For example, the string abc
has 6 distinct substrings: a
, b
, c
, ab
, bc
, and abc
, while aaa
has 3 distinct substrings: a
, aa
, and aaa
.
The input consists of multiple test cases. Each test case is provided on a separate line. The sequence of test cases is terminated by an empty line. For each test case, output the number of distinct substrings on a separate line.
Note: If the input string is empty, consider the number of distinct substrings to be 0.
inputFormat
The input is read from stdin and consists of several lines. Each non-empty line represents one test case containing a single string s. The input is terminated by an empty line.
Example:
abc aaa
outputFormat
For each test case, output an integer on a separate line representing the number of distinct substrings in the input string.
Example:
6 3## sample
abc
aaa
6
3
</p>