回文词

package 第三章;


import java.util.Scanner;


/*
 * 输入一个字符串,判断它是否为回文串以及镜像串。
 * 输入字符串保证不含数字0.
 * 所谓回文串,就是反转以后和原串相同,如abba和madam。
 * 所有镜像串,就是左右镜像之后和原串相同,如2S和3AIAE。
 * 注意,并不是每个字符在镜像之后都能得到一个合法字符。
 * 在本题中,每个字符的镜像如图所示(空白项表示该字符镜像后不能得到一个合法字符)。
输入的每行包含一个字符串(保证只有上述字符。不含空白字符),判断它是否为回文串和镜像串(共4种组合)。每组数据之后输出一个空行。


样例输入:


NOTAPALINDROME


ISAPALINILAPASI


2A3MEAS


ATOYOTA


样例输出:


NOTAPALINDROME  --  is not a palindrome.


ISAPALINILAPASI  --  is a regular palindrome.


2A3MEAS --  is a mirrored string.


ATOYOTA  --  is a mirrored palindrome.
 */
public class 回文词 {
static String str="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
String n=in.next();

// System.out.println(str.length());
boolean h=true;
boolean m=true;
for(int i=0;i<(n.length()+1)/2;i++)
{

if(n.charAt(i)!=n.charAt(n.length()-i-1))
{
h=false;
}
if(f(n.charAt(i))!=n.charAt(n.length()-i-1)) {
m=false;
}
}
if(h) {
System.out.println("huiwen");
}
else {
System.out.println("not huiwen");
}
if(m) {
System.out.println("jingxiang");
}
else {
System.out.println("not jingxiang ");
}
}


private static char f(char c) {
// TODO Auto-generated method stub
if(c>='A'&&c<='Z') {
return str.charAt(c-'A');
}
else {
return str.charAt(c-'0'+25); 
}
}


}

猜你喜欢

转载自blog.csdn.net/liuyaoyun/article/details/79342214