Palindromes
InterviewTime limit1sMemory limit128 MB
For each string, decide whether it reads the same backward and whether replacing each character by its mirror and reversing gives the same string.
- Level
Easy3 of 10
- Topics
- String, Implementation, Two pointers, Hash map
- Solved
- No attempts yet
Problem
A regular palindrome is a string of numbers or letters that reads the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it reads the same from left to right as from right to left.
A mirrored string is a string that stays the same when each of its characters is replaced by its reverse (its mirror image; if it has one, see the table below) and the resulting string is read backward. For example, "3AIAE" is a mirrored string because "A" and "I" are their own reverses, and "3" and "E" are each other's reverses.
A mirrored palindrome is a string that satisfies both the palindrome condition and the mirrored-string condition. For example, "ATOYOTA" is a mirrored palindrome: reading it backward gives the original string, and replacing every character by its reverse and reading the result backward also gives the original string. Of course, "A", "T", "O", and "Y" are all their own reverses.
The complete list of valid characters and their reverses is given below. A blank cell means the character has no reverse.
Note: 0 (zero) and O (the letter) are considered the same character, so only the letter "O" is a valid character.
Input
The input consists of strings, one per line, each made up of 1 to 20 valid characters. No string contains an invalid character. Your program should read until the end of file.
Output
For each input string, print the string starting in column 1, immediately followed by exactly one of the four phrases below.
-- is not a palindrome.if it is neither a palindrome nor a mirrored string-- is a palindrome.if it is a palindrome but not a mirrored string-- is a mirrored string.if it is a mirrored string but not a palindrome-- is a mirrored palindrome.if it is both a palindrome and a mirrored string
Thus each output line has the form <string> -- <phrase>. Print one blank line between consecutive output lines.