CF1873G.ABBC or BACB

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss made up of characters A\texttt{A} and B\texttt{B} . Initially you have no coins. You can perform two types of operations:

  • Pick a substring ^\dagger AB\texttt{AB} , change it to BC\texttt{BC} , and get a coin.
  • Pick a substring ^\dagger BA\texttt{BA} , change it to CB\texttt{CB} , and get a coin.

What is the most number of coins you can obtain? ^\dagger A substring of length 22 is a sequence of two adjacent characters of a string.

输入格式

The input consists of multiple test cases. The first line of the input contains a single integer tt ( 1t10001 \leq t \leq 1000 ) — the number of test cases.

The only line of each test case contains the string ss ( 1s21051 \leq |s| \leq 2 \cdot 10^5 ). All characters of ss are either A\texttt{A} or B\texttt{B} .

The sum of the lengths of ss over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output a single integer — the maximum number of coins you can obtain.

输入输出样例

  • 输入#1

    8
    ABBA
    ABA
    BAABA
    ABB
    AAAAAAB
    BABA
    B
    AAA

    输出#1

    2
    1
    3
    1
    6
    2
    0
    0

说明/提示

In the first test case you can perform the following operations to get 22 coins: $$$$\color{red}{\texttt{AB}}\texttt{BA} \to \texttt{BC}\color{red}{\texttt{BA}} \to \texttt{BCCB} $$

In the second test case you can perform the following operation to get 11 coin: $$ \color{red}{\texttt{AB}}\texttt{A} \to \texttt{BCA} $$

In the third test case you can perform the following operations to get 33 coins: $$ \color{red}{\texttt{BA}}\texttt{ABA} \to \texttt{CBA}\color{red}{\texttt{BA}} \to \texttt{C}\color{red}{\texttt{BA}}\texttt{CB} \to \texttt{CCBCB} $$$$

首页