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

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.

题目大意:

回文词(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:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> char str[1000], mir[1000];
char mirror[]={"1SE Z 8 A 3 HIL JM O 2TUVWXY5"}; int main(){
int len;
int i, flag1, flag2;
while(scanf("%s", str)!=EOF){ len = strlen(str);
for(i = 0; i<len; i++){ /*镜像选择*/
mir[len-i-1] = mirror[str[i]-'1'];
}
mir[len] = '\0'; /*最后要有结束的符号*/ flag1=flag2=0; /*标记的初始化,0代表是,非0代表不是*/
for(i = 0; i<=(len/2); i++){ /*判断是不是回文串*/
if(str[i]!=str[len-i-1]){
flag1 = 1;
break;
}
} flag2 = strcmp(mir, str); /*判断是不是镜像串*/ printf("%s -- ", str);
if(flag1!=0&&flag2!=0){
printf("is not a palindrome.");
}
else if(flag1==0&&flag2!=0){
printf("is a regular palindrome.");
}
else if(flag1!=0&&flag2==0){
printf("is a mirrored string.");
}
else if(flag1==0&&flag2==0){
printf("is a mirrored palindrome.");
}
printf("\n\n");
}
}

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. [转]Android调用so文件(C代码库)方法详解

    一.为什么调用c的dll要用源码编译成so库 Android系统是基于linux内核的移动终端系统,而dll是在windows环境下生成和调用的c库,所以不可以直接为android系统调用. 二.安装 ...

  2. 《C++ primer》--第9章

    习题9.2 创建和初始化一个vector对象有4种方式,为每种方式提供一个例子. 解答: 分配指定数目的元素,并对这些元素进行值初始化: vector<int> ivec(10);     ...

  3. 《Python 学习手册4th》 第八章 列表与字典

    ''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容 (每天看42页内容,可以保证月底看完此书) “重点 ...

  4. 试验笔记 - Eclipse的.class反编译插件

    常用的反编译工具有: JAD Java Decompiler Download Mirror(?) http://varaneckas.com/jad/ JadClipse (较好) http://j ...

  5. 数据库表中MAX ID获取,确保每次调用没有重复工具类(NumberUtil)

    下面这个类是获取数据库中一个字段的最大值.配置在数据库中. public class NoFactory { private final static Logger cLogger = Logger. ...

  6. 关于jQuery中,animate、slide、fade等动画的连续触发、滞后反复执行的bug的个人解决办法

    照例,现在开头讲个这个问题发生的背景吧: 因为最近要做个操作选项的呼出,然后就想到了用默认隐藏,鼠标划过的时候显示的方法. 刚开始打算添加一个class="active",直接触发 ...

  7. 各个城市优步uber注册司机官网地址汇总

    uber城市 开通uber城市 开通优步城市 哪些城市开通了uber   哪些城市开通了优步 分类: uber专车资讯 作为专车模式的创立者,Uber公司很早就进入了中国区域.优步在中国市场也是胸怀大 ...

  8. WordPress的SEO技术

    原文:http://blog.wpjam.com/article/wordpress-seo/ 文章目录[隐藏] 内容为王 页面优化 标题 链接(URL) Meta 标签 语义化 H1 H2 H3 等 ...

  9. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇03:子弹发射》

    3.子弹发射 子弹发射概述: 在打飞机游戏中,子弹是自动发射的.子弹与子弹之间间隔一定的时间,玩家通过上下左右控制游戏角色,来达到躲避敌人及击中敌人的操作. 发射原理: 抽象理解为有两个容器存放子弹, ...

  10. bash里,echo对换行符的处理

    echo -e "#include <stdio.h>\nint main()\n{\n printf(\"hello world\\\n\");\n ret ...