cswork / OA打开练习工作台

MicrosoftOA #6

Three Consecutive Replace — Max Operations

估计中等可在线判题

考点(AI 标注)贪心调度字符串哈希计数

Choose three consecutive characters where the first two are equal and the third is different, and replace the third with the character of the first two. Each operation only replaces and never deletes. Find the maximum number of operations that can be performed. The original site's walkthrough shortened the string; this site keeps the original length.

输入格式

One line of 3..200000 lowercase English letters.

输出格式

Output a single integer, the answer.

样例 1

输入:

aabaab

输出:

2

样例 2

输入:

abc

输出:

0

样例 3

输入:

aab

输出:

1

样例说明

Example 1: in aabaab, first change the last b to a, then change the b at the third position to a, giving aaaaaa, for 2 operations.

Example 2: there is no pair of equal adjacent characters, so no operation is possible; the answer is 0.

Example 3: the only triple aa b changes b to a, so the answer is 1.