#abc329c. C - Count xxx
C - Count xxx
Score : points
问题描述
给定一个长度为 的由小写英文字母组成的字符串 。
找出 中由单一字符重复构成的非空子串的数量。这里,即使两个子串以不同的方式获得,只要它们作为字符串相等,就不加以区分。
的非空子串是指通过从 的起始处删除零个或多个字符,并从结尾处删除零个或多个字符后得到的长度至少为一的字符串。例如,ab
和 abc
是 abc
的非空子串,而 ac
和空字符串则不是。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of lowercase English letters.
Find the number of non-empty substrings of that are repetitions of one character. Here, two substrings that are equal as strings are not distinguished even if they are obtained differently.
A non-empty substring of is a string of length at least one obtained by deleting zero or more characters from the beginning and zero or more characters from the end of . For example, ab
and abc
are non-empty substrings of abc
, while ac
and the empty string are not.
Constraints
- is a string of length consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print the number of non-empty substrings of that are repetitions of one character.
Sample Input 1
6
aaabaa
Sample Output 1
4
The non-empty substrings of that are repetitions of one character are a
, aa
, aaa
, and b
; there are four of them. Note that there are multiple ways to obtain a
or aa
from , but each should only be counted once.
Sample Input 2
1
x
Sample Output 2
1
Sample Input 3
12
ssskkyskkkky
Sample Output 3
8
update @ 2024/3/10 01:54:02