Gym 101138B Pen Pineapple Apple Pen【水题】

Description

standard input/output
Statements

PPAP, which stands for Pen Pineapple Apple Pen, is an unusual song and dance that went viral in the Internet recently. It's about merging a pen with either an apple or a pineapple, and then merging those together into more complicated structures.

structure is either one of mentioned items (a pen, an apple or a pineapple) or a result of combining two structures. In the former case we say a structure is basic.

The size of a basic structure is 1. The size of any other structure is equal to the sum of sizes of two structures merged into this one.

Two structures can be merged if one of the following conditions holds true:

  1. Both structures are basic and exactly one of them is a pen.
  2. None of two structures are basic and their sizes are equal.

A structure can be represented by a string of length equal to the size of the structure. A basic structure is represented by "A" (if it's an apple) or by "P" (if it's a pen or a pineapple). When a structure represented by a string w1 and a structure represented by a string w2 are merged together, they create a structure represented by a string w1w2 (strings are concatenated). The order of two merged structures matters becausew1w2 may be different that w2w1.

You are given T test cases, each with one string si consisting of characters 'A' and 'P'. Your task is to check whether it's possible to get a structure represented by such a string. Print "YES" or "NO" in a separate line, without the quotes.

Input

The first line of the input contains an integer T (1 ≤ T ≤ 10) — the number of test cases.

Each of the next T lines contains one string si (1 ≤ |si| ≤ 100), describing one test case. A string siconsists of characters 'A' and 'P' only.

Output

For each test case in a separate line print "YES" (without the quotes) if it's possible to get a structure represented by the given string, and "NO" otherwise (without the quotes).

Sample Input

Input
4
PPAP
A
AAAA
PPAPP
Output
YES
YES
NO
NO

Hint

In the first test case, one valid way is to merge a pen and a pineapple to get "PP", then merge an apple and a pen to get "AP", and finally merge two created structured in the order ("PP""AP"). The final structure is represented by "PPAP", as required.


/*
    题意:给定一个字符串,问你是否能通过两种操作的得到,
          操作1:对于两个长度为1的子串,若有一个为P则可以合并
          操作2:对于两个长度不为1的子串,若两个子串的长度相等则可以合并
    类型:水题
    分析:只要字符串的长度满足2^k并且每两个字符含有一个P则可以得到该字符串
*/
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 150;
int p[maxn];
char s[maxn];
int main()
{
    for(int i=1;i<=100;i*=2){
        p[i]=1;
    }
    int t;cin>>t;
    while(t--){
        scanf("%s",s);
        int len=strlen(s);
        if(p[len]==0)puts("NO");
        else{
            int flag=1;
            for(int i=0;i<len;i+=2){
                if(s[i]!='P'&&s[i+1]!='P'){
                    flag=0;
                }
            }
            if(len==1)flag=1;
            if(flag)puts("YES");
            else puts("NO");
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值