Description
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 "3AIAE" is a mirrored string because "A" and "I"are 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 mirrored string. The string"ATOYOTA" 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.
Character | Reverse | Character | Reverse | Character | Reverse |
A | A | M | M | Y | Y |
B | N | Z | 5 | ||
C | O | O | 1 | 1 | |
D | P | 2 | S | ||
E | 3 | Q | 3 | E | |
F | R | 4 | |||
G | S | 2 | 5 | Z | |
H | H | T | T | 6 | |
I | I | U | U | 7 | |
J | L | V | V | 8 | 8 |
K | W | W | 9 | ||
L | J | X | 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
Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.
Output
For each input string, you should 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 string |
Note 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.
Sample Input
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
Sample 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
第一次码这个oj 一个锻炼代码能力的题目 纯暴力
给你一个串
判断1 A regular palindrome 是否是回文串 slove1()
判断2 A mirrored string 串中字符按要求变换后 倒着读入是否与原串相同 slove2()
然后根据上述 判断 输出结果
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<map> 5 using namespace std; 6 char a[50]; 7 int panduan1,panduan2; 8 map<char,char> mp; 9 int slove1() 10 { 11 int len=strlen(a); 12 int jishu=len-1,gg=0;; 13 for(int i=0; i<(len)/2; i++) 14 { 15 if(a[i]==a[jishu]) 16 gg++; 17 jishu--; 18 } 19 if(gg==len/2) 20 return 1; 21 return 0; 22 } 23 int slove2() 24 { 25 mp['A']='A'; 26 mp['B']='*'; 27 mp['C']='*'; 28 mp['D']='*'; 29 mp['E']='3'; 30 mp['F']='*'; 31 mp['G']='*'; 32 mp['H']='H'; 33 mp['I']='I'; 34 mp['J']='L'; 35 mp['K']='*'; 36 mp['L']='J'; 37 mp['M']='M'; 38 mp['N']='*'; 39 mp['O']='O'; 40 mp['P']='*'; 41 mp['Q']='*'; 42 mp['R']='*'; 43 mp['S']='2'; 44 mp['T']='T'; 45 mp['U']='U'; 46 mp['V']='V'; 47 mp['W']='W'; 48 mp['X']='X'; 49 mp['Y']='Y'; 50 mp['Z']='5'; 51 mp['1']='1'; 52 mp['2']='S'; 53 mp['3']='E'; 54 mp['4']='*'; 55 mp['5']='Z'; 56 mp['6']='*'; 57 mp['7']='*'; 58 mp['8']='8'; 59 mp['9']='*'; 60 int len=strlen(a); 61 int jishu=len-1; 62 int gg=0; 63 for(int i=0; i<len; i++) 64 { 65 if(a[i]==mp[a[jishu]]) 66 gg++; 67 jishu--; 68 } 69 if(gg==len) 70 return 1; 71 return 0; 72 } 73 int main() 74 { 75 while(scanf("%s",a)!=EOF) 76 { 77 //getchar(); 78 panduan1=slove1(); 79 panduan2=slove2(); 80 if(panduan1) 81 { 82 if(panduan2) 83 cout<<a<<" -- is a mirrored palindrome."<<endl; 84 else 85 cout<<a<<" -- is a regular palindrome."<<endl; 86 } 87 else 88 { 89 if(panduan2) 90 cout<<a<<" -- is a mirrored string."<<endl; 91 else 92 cout<<a<<" -- is not a palindrome."<<endl; 93 } 94 cout<<endl; 95 memset(a,0,sizeof(a)); 96 97 } 98 return 0; 99 }