308812: CF1579A. Casimir's String Solitaire

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Casimir's String Solitaire

题意翻译

卡西米尔有一些由大写字母'A''B''C'组成的字符串s,他每次可以进行如下操作: - **同时删掉一个字母'A'和一个字母‘B’** - **或者是同时删掉一个字母'B'和一个字母'C'** 可以发现,每进行一次操作,字符串的长度正好会减少2. 每一次卡西米尔都可以选择一种操作方法对已有字符串进行操作. 例如字符串"ABCABC",卡西米尔就可以把它操作成字符串"ACBC"(同时删除位于第二位的'B'和位于第四位的'A').当然,卡西米尔还可以把它变成其它字符串. 现在他希望能把这些字符串经过若干次操作后变成空串(即什么都没有的字符串),请你帮帮他。 ### 输入格式 ##### 本题会输入多组数据 第一行输入t(1≤t≤1000),代表共有t组数据. 接下来t行,每行一个字符串s,即由'A''B''C'组成的字符串. 设n为s的长度,则1≤n≤50. ### 输出格式 输出t行,每行一个答案,为对应字符串能否变为空串的答案.若能,则输出"YES",否则输出"NO".大小写客户换,如:在可以时输出"Yes"会被认为是有效答案.

题目描述

Casimir has a string $ s $ 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 $ 2 $ . All turns are independent so for each turn, Casimir can choose any of two possible actions. For example, with $ s $ $ = $ "ABCABC" he can obtain a string $ s $ $ = $ "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 $ s $ 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?

输入输出格式

输入格式


The first line contains an integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases. Each test case is described by one string $ s $ , for which you need to determine if it can be fully erased by some sequence of turns. The string $ s $ consists of capital letters 'A', 'B', 'C' and has a length from $ 1 $ to $ 50 $ letters, inclusive.

输出格式


Print $ t $ 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).

输入输出样例

输入样例 #1

6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC

输出样例 #1

NO
YES
NO
NO
YES
YES

Input

题意翻译

卡西米尔有一些由大写字母'A''B''C'组成的字符串s,他每次可以进行如下操作: - **同时删掉一个字母'A'和一个字母‘B’** - **或者是同时删掉一个字母'B'和一个字母'C'** 可以发现,每进行一次操作,字符串的长度正好会减少2. 每一次卡西米尔都可以选择一种操作方法对已有字符串进行操作. 例如字符串"ABCABC",卡西米尔就可以把它操作成字符串"ACBC"(同时删除位于第二位的'B'和位于第四位的'A').当然,卡西米尔还可以把它变成其它字符串. 现在他希望能把这些字符串经过若干次操作后变成空串(即什么都没有的字符串),请你帮帮他。 ### 输入格式 ##### 本题会输入多组数据 第一行输入t(1≤t≤1000),代表共有t组数据. 接下来t行,每行一个字符串s,即由'A''B''C'组成的字符串. 设n为s的长度,则1≤n≤50. ### 输出格式 输出t行,每行一个答案,为对应字符串能否变为空串的答案.若能,则输出"YES",否则输出"NO".大小写客户换,如:在可以时输出"Yes"会被认为是有效答案.

加入题单

上一题 下一题 算法标签: