Ultraviolet A 401-Palindromes (simulation)
Palindromes Time Limit: 3000 MS Memory Limit: 0KB 64bit IO Format: % lld & % llu Submit StatusDescription A regular palindrome is a string of numbers or letters that is the same forward as backward. for example, the string ABCDEDCBA is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left. A mirrored string is a string for which when Each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same as the original string. for example, the string 3 AIAE is a mirrored string because A and Iare their own reverses, and 3 and E are each others 'reverses. A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirr Ored string. the stringATOYOTA is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string. of course, A, T, O, and Y are all their own reverses. A list of all valid characters and their reverses is as follows. C Haracter Reverse Character ReverseA a m y yb n z 5C O 1 1D P 2 SE 3 Q 3 ef r 4g s 2 5 zh h t 6 I U 7 j l v 8 8 k w 9 l j x Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter 0 is a valid character. input consists of strings (one per line) each of which will consist of one to twenty valid characters. there wi Ll be no invalid characters in any of the strings. your program shocould read to the end of file. output For each input string, you shocould print the string starting in column 1 immediately followed by exactly one of the following strings. string criteria -- is not a palindrome. if the string is not a palindrome and is not a mirrored string -- is a regular palindrome. if the string is a palindrome and Is not a mirrored string -- is a mirrored string. if the string is not a palindrome and is a mirrored string -- is a mirrored palindrome. if the string is a palindrome and is a mirrored stringNote that the output line is to include the-'s and spacing exactly as shown in the table above and demonstrated in the Sample Output below. in addition, after each output line, you must print an empty line. sa Mple Input notapalindrome isapalinilapasi 2A3MEAS ATOYOTASample Output NOTAPALINDROME -- is not a palindrome. ISAPALINILAPASI -- is a regular palindrome. 2A3MEAS -- is a mirrored string. ATOYOTA -- is a mirrored palindrome. hint use the C ++'s class of string will be convenient, but not a must this question involves two types of strings, one is the echo string, the other is the image string, the image string is the same as the forward and backward strings. There are four situations: (1) the image string is the same as the image string (2) the image string is not the image string (3) the image string is not the image string (4) it is neither an image string nor a reply string. Give you a string to determine the situation. # Include using namespace std; char a [] = ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789; char B [] = A 3 HIL JM O 2TUVWXY51SE Z 8; char str [1010]; int is_p (char str []) {int I; int len = strlen (str); for (I = 0; I <(len/2); I ++) {if (str [I]! = Str [len-i-1]) return 0;} return 1;} int is_m (char str []) {int I, j; int len = strlen (str ); if (len = 1) {for (I = 0; I <35; I ++) {if (str [0] = a [I]) break ;} if (I = 35 | str [0]! = B [I]) return 0; else return 1;} else if (len> 1) {for (I = 0; I <(len/2 + 1 ); I ++) {for (j = 0; j <35; j ++) {if (str [I] = a [j]) break ;} if (j = 35 | str [len-i-1]! = B [j]) return 0;} return 1 ;}} int main () {int flag1, flag2; while (~ Scanf (% s, str) {flag1 = is_p (str); flag2 = is_m (str); // printf (% d <, flag1, flag2); if (flag1 & flag2) {printf (% s -- is a mirrored palindrome ., str);} else if (flag1 &&! Flag2) {printf (% s -- is a regular palindrome., str);} else if (flag2 &&! Flag1) {printf (% s -- is a mirrored string., str);} else if (! Flag2 &&! Flag1) {printf (% s -- is not a palindrome., str) ;}} return 0 ;}