cswork / OA打开练习工作台

AmazonOA #49

Find Time (Mutation Removal)

估计中等可在线判题

考点(AI 标注)字符串动规入门

In each round, every mutation character whose immediate left neighbor is a non-mutation character deletes that neighbor, and all deletions happen simultaneously; mutation characters never delete each other. Find the number of rounds until no more deletions occur, or 0 if no deletion ever happens.

输入格式

The first line contains the lowercase genome (length 1..100000), and the second line contains a single lowercase mutation character.

输出格式

Output a single integer answer.

样例 1

输入:

tamem
m

输出:

2

样例 2

输入:

abc
z

输出:

0

样例 3

输入:

mmabm
m

输出:

2

样例说明

Example 1: in the first round, the two m delete a and e respectively, giving tmm; in the second round, the first m deletes t, leaving mm, so the answer is 2. Example 2: there are no mutation characters, 0 rounds. Example 3: the last m deletes b first and then a, leaving mmm after two rounds.