#K47122. Palindrome Queries
Palindrome Queries
Palindrome Queries
You are given two strings A and B, and a set of queries. Each query is a two‐character string that determines how you concatenate A and B. The query can be one of the following:
• AA: Concatenate A with A. • AB: Concatenate A with B. • BA: Concatenate B with A. • BB: Concatenate B with B.
A string is considered a palindrome if it reads the same backward as forward, i.e., ( s = s^{R} ). For each query, output "YES" if the concatenated string is a palindrome, and "NO" otherwise.
For example, if A = "abc" and B = "cba", then for the query AB (which forms "abccba"), the output is "YES".
inputFormat
The input is read from stdin and consists of multiple lines as follows:
- The first line contains the string A.
- The second line contains the string B.
- The third line contains an integer Q, representing the number of queries.
- The next Q lines each contain a query, which is one of "AA", "AB", "BA", or "BB".
outputFormat
For each query, print a line to stdout with either "YES" or "NO" indicating whether the resulting concatenated string is a palindrome.## sample
abc
cba
4
AA
AB
BA
BB
NO
YES
YES
NO
</p>