Palindromes

Time Limit:3000MS     Memory Limit:0KB     64bit 
                                                                                        IO Format:%lld & %llu

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

【思路】

回文 --即从左至右与从右至左一样,例如:abccab 、aaa、abcba.......

镜像字符串--字符串里的字符都属于镜像字符,且从左至右与字符镜像呈回文。例如:AEH3A(A-A E-3).....

建立两个方法判断回文与判断镜像字符串(见代码)。

回文部分读者自看。

判断镜像字符串,传人字符串,先判断字符串中是否有字符不属于镜像字符,如果有直接返回false,没有在进行下一步扫描

本代码中建立了对应的x1字符数组,存放对应的镜像。x数组存放镜像字符,x1对应x存放其镜像。

从头开始扫描,i从头,j从尾扫描。在x字符数组中扫描找到其c[i]字符在x数组对应的下标k(x1[k]为其镜像),然后判断c[j]与x[k]是否相等(即对应的尾部字符是否是其字符对应的镜像字符),若相等镜像匹配成功,依次扫描,扫描到最后返回true。

【小坑,其中所有的‘0’(零)用‘O’(哦)来代替,看清楚】

 

AC代码:

import java.util.Scanner;

public class Main {
public static boolean pali(String s) {
char[] c = s.toCharArray();
int i, j;
for (i = 0, j = c.length - 1; i < j; i++, j--) {
if (c[i] != c[j]) {
return false;
}
}
return true;
} public static boolean mirr(String s) {
char[] c = s.toCharArray();
int i, j;
char[] x = new char[] { 'A', 'E', 'H', 'I', 'J', 'L', 'M', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2',
'3', '5', '8', 'O' };
for (i = 0; i < c.length; i++) {
for (j = 0; j < x.length; j++) {
if (c[i] == x[j]) {
break;
}
}
if (j == x.length) {
return false;
}
}
int k = 0;
char[] x1 = new char[] { 'A', '3', 'H', 'I', 'L', 'J', 'M', '2', 'T', 'U', 'V', 'W', 'X', 'Y', '5', '1', 'S',
'E', 'Z', '8', 'O' };
for (i = 0, j = c.length - 1; i < j; i++, j--) {
for (k = 0; k < x.length; k++) {
if (c[i] == x[k]) {
if (c[j] != x1[k]) {
return false;
}
}
}
}
return true;
} public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String s = sc.nextLine();
char[] a = s.toCharArray();
for (int i = 0; i < a.length; i++) {
if (a[i] == '0')
a[i] = 'O';
}
String str = new String(a);
if (pali(str) && mirr(str)) {
System.out.println(str + " -- is a mirrored palindrome.");
} else if (pali(str)) {
System.out.println(str + " -- is a regular palindrome.");
} else if (mirr(str)) {
System.out.println(str + " -- is a mirrored string.");
} else
System.out.println(str + " -- is not a palindrome.");
System.out.println();
}
}
}

  

hdu 1318 Palindromes的更多相关文章

  1. hdu 1318 Palindromes(回文词)

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

  2. HDU 2163 Palindromes

    http://acm.hdu.edu.cn/showproblem.php?pid=2163 Problem Description Write a program to determine whet ...

  3. HDOJ/HDU 2163 Palindromes(判断回文串~)

    Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...

  4. HDU 1544 Palindromes(回文子串)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1544 问题分析: 问题要求求出字符串的连续子串中的回文子串个数.首先,需要区分连续子串与子序列的区别. ...

  5. HDU 2029 Palindromes _easy version

    http://acm.hdu.edu.cn/showproblem.php?pid=2029 Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“ ...

  6. Palindromes

    http://acm.hdu.edu.cn/showproblem.php?pid=1318 Palindromes Time Limit: 2000/1000 MS (Java/Others)    ...

  7. hdu 3948 The Number of Palindromes

    The Number of Palindromes Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (J ...

  8. HDU - 5340 Three Palindromes(manacher算法)

    http://acm.hdu.edu.cn/showproblem.php?pid=5340 题意 判断是否能将字符串S分成三段非空回文串 分析 manacher预处理出前缀和后缀回文的位置, 枚举第 ...

  9. HDU 5340——Three Palindromes——————【manacher处理回文串】

    Three Palindromes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

随机推荐

  1. 关于idea 修改jsp文件后不能生效

    打开server 的配置界面: 其中 修改on update Action 为 Redeploy On frame deactivation 为Update classes and resources

  2. 【BZOJ 2733】【HNOI 2012】永无乡 Splay启发式合并

    启发式合并而已啦,, 调试时发现的错误点:insert后没有splay,把要拆开的树的点插入另一个树时没有把ch[2]和fa设为null,找第k大时没有先减k,,, 都是常犯的错误,比赛时再这么粗心就 ...

  3. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

  4. java-获取随机字符串

    import java.util.Random; public class getRandomString { public static String excute(int length) { St ...

  5. PV、UV、IP之间的区别与联系

    先看图: 1.什么是PV值 PV(page view)即页面浏览量或点击量,是衡量一个网站或网页用户访问量.具体的说,PV值就是所有访问者在24小时(0点到24点)内看了某个网站多少个页面或某个网页多 ...

  6. js-处理千分符

      <html> <head> <title> JS千分位处理 </title> </head> <script> functi ...

  7. Hive 按某列的部分排序 以及 删列操作

    脑袋果然还是智商不足. 涉及到的小需求: 某个表test 有一列 tc: a字符串+b字符串+c字符串 拼接组成 把test表,按b字符串排序 输出 遇到的问题: select 里面必须包含 orde ...

  8. 71.Android之长连接实现

    转载:http://blog.csdn.net/qq_23547831/article/details/51690047 本文中我们将讲解一下App的长连接实现.一般而言长连接已经是App的标配了,推 ...

  9. Linux 输出重定向>和>>的区别

    >是定向输出到文件,如果文件不存在,就创建文件:如果文件存在,就将其清空:一般我们备份清理日志文件的时候,就是这种方法:先备份日志,再用`>`,将日志文件清空(文件大小变成0字节): &g ...

  10. BZOJ4548 小奇的糖果

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...