#K60222. Counting Substrings with Specific Boundary Character
Counting Substrings with Specific Boundary Character
Counting Substrings with Specific Boundary Character
Given a string s
and a character c
, your task is to count the number of substrings of s
that start and end with c
. A substring is any contiguous sequence of characters within the string. If the character c
occurs n times in the string, then the total number of valid substrings is given by the formula: \(\frac{n(n+1)}{2}\). This problem requires efficient string processing and combinatorial counting.
inputFormat
The input consists of two lines:
- The first line contains the string
s
. - The second line contains a single character
c
.
outputFormat
Output a single integer representing the number of substrings in s
that begin and end with the character c
.
abcabc
a
3