A - Palindromes:
来源:互联网 发布:单片机入门的编程语言 编辑:程序博客网 时间:2024/06/06 19:38
A - Palindromes:
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.
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.
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
#include<cstdio>#include<cstring>#include<cctype>//#include<iostream>//using namespace std;bool mirror(char nn,char uu) {switch(nn) {case 'A':nn='A';break;case 'M':nn='M';break;case 'Y':nn='Y';break;case 'E':nn='3';break;case 'O':nn='O';break;case '0':nn='0';break;case '1':nn='1';break;case '2':nn='S';break;case '3':nn='E';break;case 'S':nn='2';break;case '5':nn='Z';break;case 'Z':nn='5';break;case 'T':nn='T';break;case 'H':nn='H';break;case 'I':nn='I';break;case 'U':nn='U';break;case 'J':nn='L';break;case 'V':nn='V';break;case '8':nn='8';break;case 'W':nn='W';break;case 'X':nn='X';break;case 'L':nn='J';break; }if (nn==uu) return true;else return false; }int main() {char a[50];bool flags,term;int n,u;int t;while (scanf("%s",a)!=EOF){t=strlen(a);flags=true;term=true;for (n=0,u=t-1;n<=u;n++,u--){if (a[n]!=a[u]) {flags=false; break;}} int l=t/2;for (int i=0;i<l;i++){if (a[i]=='B'||a[i]=='C'||a[i]=='D'||a[i]=='F'||a[i]=='G'||a[i]=='K'||a[i]=='N'||a[i]=='P'||a[i]=='Q'||a[i]=='R'||a[i]=='4'||a[i]=='6'||a[i]=='7'||a[i]=='9') {term=false;break; }term = mirror(a[i], a[t-i-1]);if (!term) {break; } }if(term && (t%2 == 1)){if(a[t/2]=='B'||a[t/2]=='C'||a[t/2]=='D'||a[t/2]=='F'||a[t/2]=='G'||a[t/2]=='K'||a[t/2]=='N'||a[t/2]=='P'||a[t/2]=='Q'||a[t/2]=='R'||a[t/2]=='4'||a[t/2]=='6'||a[t/2]=='7'||a[t/2]=='9'){term=false;}}if (flags&&term) printf("%s -- is a mirrored palindrome.\n\n" ,a);else if (flags) printf("%s -- is a regular palindrome.\n\n" ,a);else if (term) printf("%s -- is a mirrored string.\n\n" ,a);else printf("%s -- is not a palindrome.\n\n" ,a);}//system("pause");return 0; }
- A - Palindromes:
- 字符串A - Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- Palindromes
- http://www.zhihuishi.com/source/1.html
- Linux 磁盘与文件系统管理(鸟哥私房菜)
- JavaScript判断字符串是否合法
- 疯牛
- 线程、IO总结
- A - Palindromes:
- igrimace注册做陌陌注册微信注册拉手同城美团大众猫眼去哪儿uber
- AJAX及其工作原理
- lua笔试
- [LeetCode][Java] Binary Tree Level Order Traversal
- hdoj 2032 杨辉三角
- java字符流和字节流区别
- 可伸缩Web架构与分布式系统(初步)
- 工具程序试题