A and B
InterviewTime limit2sMemory limit512 MB
Given two strings of A and B, decide whether S can be turned into T using only: append A, or reverse then append B.
- Level
Medium6 of 10
- Topics
- Greedy, String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Subin was surprised to learn that some English words use only the letters A and B. AB (short for Abdominal), BAA (the sound a sheep makes), AA (a type of lava), and ABBA (the Swedish pop group) are examples.
Starting from that idea, Subin made a simple game. Given two strings and , the goal is to turn into . Only these two operations can change a string.
- Append A to the end of the string.
- Reverse the string, then append B to the end.
Write a program that decides whether these operations can turn into .
Input
The first line contains and the second line contains . Both strings consist only of the uppercase letters A and B. (, , )
Output
Print 1 if can be turned into , and 0 if it cannot.