#K41777. Palindrome Checker

    ID: 26941 Type: Default 1000ms 256MiB

Palindrome Checker

Palindrome Checker

Given a string, determine if it is a palindrome by ignoring all non-alphanumeric characters and case differences. Formally, for a string ( s ), let its cleaned version be ( s' = \text{concatenate}({ c.lower() : c \in s \text{ and } c \text{ is alphanumeric} }) ). The string is a palindrome if ( s' = \text{reverse}(s') ). You are required to process multiple test cases from standard input and output the result for each case on a new line. For each test case, output "YES" if the string is a palindrome and "NO" otherwise.

inputFormat

The input consists of multiple test cases. The first line contains an integer ( T ) (where ( T \geq 1 )), which represents the number of test cases. Each of the following ( T ) lines contains a string. Note that the string may contain spaces, punctuation, or mixed case characters.

outputFormat

For each test case, print a single line containing the answer: "YES" if the corresponding string is a palindrome when ignoring non-alphanumeric characters and case, or "NO" otherwise.## sample

6
A man a plan a canal Panama
Race Car
hello world
No lemon, no melon
abcba
Was it a car or a cat I saw
YES

YES NO YES YES YES

</p>