#C14438. Palindrome and Anagram Checker
Palindrome and Anagram Checker
Palindrome and Anagram Checker
This problem requires you to implement two functionalities: checking whether a string is a palindrome and determining if two strings are anagrams. For a palindrome check, consider only alphanumeric characters and ignore cases. For an anagram check, ignore spaces and cases.
Palindrome Condition: A string \(S\) is a palindrome if it reads the same forwards and backwards when all non-alphanumeric characters are removed and cases are ignored. That is, if \(S' = S'[::-1]\).
Anagram Condition: Two strings \(S_1\) and \(S_2\) are anagrams if, after removing spaces and converting all characters to lowercase, the sorted sequences of characters are the same.
Your program should handle multiple queries as described below.
inputFormat
The input begins with an integer \(Q\) representing the number of queries. Each query starts with a line containing an integer which is either 1
or 2
:
- If the query type is
1
, the next line contains a string \(S\) for the palindrome check. - If the query type is
2
, the next two lines contain strings \(S_1\) and \(S_2\) for the anagram check.
All input is read from standard input (stdin
).
outputFormat
For each query, output True
if the string is a palindrome or if the two strings are anagrams according to the condition, otherwise output False
. Each result should be printed on a new line to standard output (stdout
).
3
1
A man, a plan, a canal: Panama
2
listen
silent
2
apple
pale
True
True
False
</p>