#C724. Count Distinct Substrings
Count Distinct Substrings
Count Distinct Substrings
Given a string \(S\) and an integer \(K\), compute the number of distinct substrings of \(S\) that have exactly \(K\) characters. A substring is a contiguous sequence of characters in \(S\). If \(K\) is greater than the length of \(S\), the result is zero.
For example:
Input: S = "banana", K = 3 Output: 3
Here, the distinct substrings of length 3 are "ban", "ana", and "nan".
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains the string \(S\).
- The second line contains an integer \(K\), representing the desired substring length.
outputFormat
The output is a single integer printed to standard output (stdout) representing the number of distinct substrings of length \(K\) from string \(S\).
## samplebanana
3
3