#K78542. Palindrome Checker and Longest Palindromic Substring Finder
Palindrome Checker and Longest Palindromic Substring Finder
Palindrome Checker and Longest Palindromic Substring Finder
You are given a string ( s ) and must perform two tasks:
-
Check if the string is a palindrome by considering only alphanumeric characters and ignoring case. A string ( s ) is a palindrome if [ \text{clean}(s) = \text{reverse}(\text{clean}(s)) ] where ( \text{clean}(s) ) is the string after removing non-alphanumeric characters and converting to lowercase.
-
Find and output the longest palindromic substring in the original string ( s ). In case there are multiple palindromic substrings of maximum length, return the one that appears first (i.e. the leftmost).
The output should consist of two lines: the first line is either "True" or "False" depending on whether ( s ) is a palindrome (after cleaning), and the second line is the longest palindromic substring found in ( s ). Note that the longest palindromic substring is identified from the original string without any character filtering.
inputFormat
Input is provided via standard input (stdin) and consists of a single line which contains the string ( s ). The string may include spaces, punctuation, and mixed capitalization.
outputFormat
Output to standard output (stdout) with exactly two lines. The first line should be either "True" or "False" indicating whether ( s ) is a palindrome (after ignoring non-alphanumeric characters and case). The second line should be the longest palindromic substring as determined from the original string ( s ).## sample
racecar
True
racecar
</p>