#60. 统计字符串中三连字符数量
统计字符串中三连字符数量
Count Triples
Background
Congcong has recently been studying pattern recognition in strings. He discovered a special pattern he calls a "triple".
Problem Description
We'll say that a "triple" in a string is a character appearing three times in a row. Return the number of triples in the given string. The triples may overlap.
Input Format
Input is given from Standard Input in the following format.
A string .
Output Format
Output is printed to Standard Output in the following format.
An integer, representing the number of triples in the string.
Sample
abcXXXabc
1
xxxabyyyycd
3
a
0
Sample Explanation
For the first sample abcXXXabc, the character 'X' appears three times consecutively, forming one triple. So the result is 1.
For the second sample xxxabyyyycd, xxx is one triple, yyy is another triple, and the fourth 'y' with the two preceding 'y's forms another triple (i.e., from the second 'y' to the fourth 'y' of yyyy). Thus, there are 3 triples in total.
Constraints
For all test cases, the length of string does not exceed . Time limit: 1 second per test case. Memory limit: 1024 KiB per test case.