#K93102. String Game - Palindrome Checker
String Game - Palindrome Checker
String Game - Palindrome Checker
You are given a series of operations that manipulate a string. There are three types of operations:
- 1 x: Append the character
x
to the end of the string. - 2: Remove the last character of the string if it exists.
- 3: Check if the current string is a palindrome and output the result.
A string s is a palindrome if it reads the same forwards and backwards. Formally, a string s of length n is a palindrome if \( s[i] = s[n-i+1] \) for all \( 1 \le i \le n \). Note that the empty string is considered a palindrome.
Your task is to simulate these operations sequentially and output the result of each type 3 operation.
inputFormat
The first line of input contains an integer N
representing the number of operations.
Each of the next N
lines contains a single operation in one of the following formats:
1 x
(where x is a lowercase English letter)2
3
outputFormat
For each operation of type 3
, output a line containing YES
if the current string is a palindrome, or NO
if it is not.
4
1 a
1 b
1 a
3
YES
</p>