#K3166. Palindrome Checker
Palindrome Checker
Palindrome Checker
This problem requires you to check whether a given string \( s \) is a palindrome, ignoring case, spaces, and punctuation. A palindrome is a sequence that reads the same backward as forward. For example, the string "A man, a plan, a canal, Panama" is a palindrome once non-alphanumeric characters are removed and case is normalized.
Your task is to remove all characters from the input string that are not letters or digits, convert the remaining characters to lowercase, and then check if the resulting string is identical to its reverse.
The formal check can be expressed as follows: if \( s' \) is the cleaned string then the condition for a palindrome is:
\[ s' = \text{reverse}(s') \]If the condition is met, print YES
; otherwise, print NO
.
inputFormat
The input consists of a single line containing the string \( s \). The string may include letters, digits, spaces, and punctuation.
outputFormat
Output a single line: YES
if the cleaned string is a palindrome, and NO
otherwise.
madam
YES