Gym 101138B Pen Pineapple Apple Pen【水题】
来源:互联网 发布:知大势大局的名言 编辑:程序博客网 时间:2024/05/22 14:21
Description
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.
A 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:
- Both structures are basic and exactly one of them is a pen.
- 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
4PPAPAAAAAPPAPP
YESYESNONO
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;}
- Gym 101138B Pen Pineapple Apple Pen【水题】
- hdu4486 Pen Counts(水题)
- magic pen!
- Meet Pen
- GDI-Pen
- HDOJ 题目4648 Magic Pen 6(水题)
- magnet, pen, etc.
- tube, pen, etc.
- Reverse proxy pen testing
- GDI+: Pen and Brush
- Pen和Brush
- Pen、Brush对象
- wxWidgets的Pen Style
- hdu 4486 pen counts
- Uva 6174 Pen Counts
- hdu 4486 Pen Counts
- Hdu 4486 Pen Counts
- pen...for ...using
- kubernetes学习1--centOS7.2使用yum安装kubernetes
- 仿墨迹天气折线图
- 容器云最佳实践:Docker、微服务、应用容器化之Kubernetes实践
- php中的文件与目录
- 算法之租用游艇问题
- Gym 101138B Pen Pineapple Apple Pen【水题】
- Log4J的配置文件
- 解决笔记本光驱位硬盘休眠卡顿问题
- Java中的IO框架流三
- txt转化csv的接口(子函数)
- 290. Word Pattern
- 读书了,不可思议
- 崩溃日志 全局crash捕获
- mysql普通日志(general_log)详解(5.7)