Palindromes 

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 thereforeONLY 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

  1. NOTAPALINDROME
  2. ISAPALINILAPASI
  3. 2A3MEAS
  4. ATOYOTA

Sample Output

  1. NOTAPALINDROME -- is not a palindrome.
  2.  
  3. ISAPALINILAPASI -- is a regular palindrome.
  4.  
  5. 2A3MEAS -- is a mirrored string.
  6.  
  7. ATOYOTA -- is a mirrored palindrome.

题目大意:

回文词(palindrome)就是顺序逆序都相同的词句,例如“ABCDEDCBA”。

镜像词语,就是两个词成镜像相反,例如“A”、:"I"都是自己是自己的镜像,“3”和“E”互成镜像,题目中也列出了大写字母以及数字的镜像。

题目要求就是判断一个字符串是否是回文串、镜像串,根据判断结果有四种解答,分别是:

字符串 标准
" -- is not a palindrome." 既不是回文串,也不是镜像串        
" -- is a regular palindrome." 是回文串,但不是镜像串
" -- is a mirrored string." 是镜像串,但不是回文串
" -- is a mirrored palindrome." 既是回文串,又是镜像串

解析:
首先用一个字符串数组将所有的镜像单词存储下来char mirror[]={"1SE Z  8        A   3  HIL JM O   2TUVWXY5"};(从1~Z,根据ASCII码,数字后留七个空格,才到大写字母),然后进行镜像的选择。

注意:
1)回文的时候,可能有人使用strrev函数,但它不属于ANSI C标准,所以会出现错误(Compilation error),所以可以自己写回文函数。
    2)不知道为什么,写了一个回文函数,但是一直RE,也没发现有错误,所以我就进行直接首尾比较,判断回文串。
    3)为了避免镜像串也要进行一次回文,所以在进行镜像翻译的时候做了一些改变!


CODE:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char str[1000], mir[1000];
  6. char mirror[]={"1SE Z 8 A 3 HIL JM O 2TUVWXY5"};
  7.  
  8. int main(){
  9. int len;
  10. int i, flag1, flag2;
  11. while(scanf("%s", str)!=EOF){
  12.  
  13. len = strlen(str);
  14. for(i = 0; i<len; i++){ /*镜像选择*/
  15. mir[len-i-1] = mirror[str[i]-'1'];
  16. }
  17. mir[len] = '\0'; /*最后要有结束的符号*/
  18.  
  19. flag1=flag2=0; /*标记的初始化,0代表是,非0代表不是*/
  20. for(i = 0; i<=(len/2); i++){ /*判断是不是回文串*/
  21. if(str[i]!=str[len-i-1]){
  22. flag1 = 1;
  23. break;
  24. }
  25. }
  26.  
  27. flag2 = strcmp(mir, str); /*判断是不是镜像串*/
  28.  
  29. printf("%s -- ", str);
  30. if(flag1!=0&&flag2!=0){
  31. printf("is not a palindrome.");
  32. }
  33. else if(flag1==0&&flag2!=0){
  34. printf("is a regular palindrome.");
  35. }
  36. else if(flag1!=0&&flag2==0){
  37. printf("is a mirrored string.");
  38. }
  39. else if(flag1==0&&flag2==0){
  40. printf("is a mirrored palindrome.");
  41. }
  42. printf("\n\n");
  43. }
  44. }

401 Palindromes(回文词)的更多相关文章

  1. hdu 1318 Palindromes(回文词)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1318 题意分析:输入每行包含一个字符串,判断此串是否为回文串或镜像串. 表面上看这道题有些复杂,如果能 ...

  2. UVa-401 Palindromes回文词

    虽然是水题,但是容易错.参照了紫书的代码可以写的很简洁.主要还是注意常量数组的使用,能让代码变得简单许多 #include <iostream> #include <cstdio&g ...

  3. 回文词 (Palindromes,Uva401)

    例题 3-3 回文词 (Palindromes,Uva401) 输入一个字符中,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有 ...

  4. CSU 1328: 近似回文词

    省赛的A题...现场都没什么人做...其实就一暴力水题......坑死了... 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1 ...

  5. 字符串 - 近似回文词 --- csu 1328

    近似回文词 Problem's Link:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 analyse: 直接暴力枚举每一个终点,然后枚举 ...

  6. csuoj 1328: 近似回文词

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 1328: 近似回文词 Time Limit: 1 Sec  Memory Limit: 1 ...

  7. Vijos1327回文词【动态规划】

    回文词 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得到的 结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个回文词.你的任务是写 一个程序,求出将给定字符 ...

  8. 回文词_KEY

    回文词 (palin.pas/c/cpp) [问题描述] 回文词是一种对称的字符串--也就是说,一个回文词,从左到右读和从右到左读得的结果是一样的.任意给定一个字符串,通过插入若干字符,都可以变成一个 ...

  9. csu-1328 近似回文词 和 最长回文字符串

    原博文地址:http://blog.csdn.net/u012773338/article/details/39857997 最长回文子串 描述:输入一个字符串,求出其中最长的回文子串.子串的含义是: ...

随机推荐

  1. 兼容个个浏览器Cookie的读写

    function readCookie(name) {   var nameEQ = name + "=";   var ca = document.cookie.split('; ...

  2. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  3. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(6)

    创建一个新文档(Creating a new document) 现在我们将尝试索引一些文档.对于我们的示例,让我们想象我们正在为我们的博客建立某种CMS.实体之一是博客的文章.使用JSON记法,在以 ...

  4. HDU5777 domino (BestCoder Round #85 B) 思路题+排序

    分析:最终的结果肯定会分成若干个区间独立,这些若干个区间肯定是独立的(而且肯定是一边倒,左右都一样) 这样想的话,就是如何把这n-1个值分成 k份,使得和最小,那么就是简单的排序,去掉前k大的(注意l ...

  5. [Tommas] 一种有效的测试策略(转)

    在最近的一个大型项目中,我们在早期就定下了一个目标:不会在软件中使用大量QA人员专注于手工测试.通过手工测试发现bug极其耗时且成本高昂,这促使团队尝试尽可能的将质量内嵌到产品内部.但这并不意味着手工 ...

  6. 对象指针与this指针

    对象指针分为三大类 [1]指向对象的指针 [2]指向对象成员的指针(数据类) [3]指向对象成员的指针(函数类) #include<iostream> using namespace st ...

  7. salt 批量部署与配置

    salt是啥? salt是一个大型分布式的配置管理系统(安装升级卸载软件,检测环境),也是一个远程命令执行系统. salt 分为 master和minion,master顾名思义就是老大,管理子节点: ...

  8. 数据库(class0507)

    局部变量_先声明再赋值 声明局部变量 DECLARE @变量名 数据类型 DECLARE @name varchar(20) DECLARE @id int 赋值 SET @变量名 =值 --set用 ...

  9. Camera图片特效处理综述(Bitmap的Pixels处理、Canvas/paint的drawBitmap处理、旋转图片、裁截图片、播放幻灯片浏览图片<线程固定时间显示一张>)

    一种是直接对Bitmap的像素进行操作,如:叠加.边框.怀旧.(高斯)模糊.锐化(拉普拉斯变换). Bitmap.getPixels(srcPixels, 0, width, 0, 0, width, ...

  10. [转]Erlang不能错过的盛宴

    Erlang不能错过的盛宴 (快步进入Erlang的世界) 作者:成立涛 (litaocheng@gmail.com) 作为程序员,我们曾经闻听很多“业界动态”,“技术革新”,曾经接触很多“高手箴言” ...