P3 - ABBA

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 32M

Authors:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Jeremy really likes the Swedish rock band ABBA. So much so, he is obsessed with strings consisting of the letters A and B. He has 2 strings S and T, where S and T both only have either A or B for its letters, and T is longer or as long as S. Jeremy has 2 types of operations. The first operation adds an A to the end of the string. The second operation reverses the string, and then adds a B to the end of the string. He wonders if there is a sequence of operations to transform S to T.

Input Specification

The first line will be the integer N (1\leq N \leq5), the number test cases. The next 2N lines contains strings S and T, each on a separate line with S before T. The length of S and T are at most 1000. 50% of points will have the length of S and T at most 10.

Output Specification

YES if there is S can be transformed to T, NO otherwise.

Sample Input 1

3
ABBA
ABBAAAA
AB
BABA
A
B

Sample Output 1

YES
YES
NO

Comments

There are no comments at the moment.