A. Casimir‘s String Solitaire

1. Problem

Casimir has a string ss which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:

  • he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);
  • or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent).

Therefore, each turn the length of the string is decreased exactly by 22. All turns are independent so for each turn, Casimir can choose any of two possible actions.

For example, with ss == "ABCABC" he can obtain a string ss == "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.

For a given string ss determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?

Input

The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

Each test case is described by one string ss, for which you need to determine if it can be fully erased by some sequence of turns. The string ss consists of capital letters 'A', 'B', 'C' and has a length from 11 to 5050 letters, inclusive.

Output

Print tt lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

Example

input

6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC

output

NO
YES
NO
NO
YES
YES

2. Analysis

When the number of letters A and C equals the number of letters B, there is a way to fully erase the corresponding string.

3. Accepted Code

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int t;
    scanf("%d",&t);  //t组输入
    int i;
    getchar();  //吃掉t后的回车
    for(i=0; i<t; i++)
    {
        int numAC=0, numB=0;  //字母A和C的数量numAC,字母B的数量numB
        char ch;
        ch=getchar();
        while( ch != '\n' )  //以回车作为每组输入的结束标志
        {
            if(ch=='A' || ch=='C')
            {
                numAC++;
            }
            else if(ch=='B')
            {
                numB++;
            }
            ch=getchar();
        }

        if(numAC == numB)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值