palindrome

package Chapter 3;


import java.util.Scanner;


/*
 * Enter a string to determine whether it is a palindrome or an image string.
 * The input string is guaranteed to not contain the number 0.
 * The so-called palindrome is the same as the original string after inversion, such as abba and madam.
 * All image strings are the same as the original string after the left and right images, such as 2S and 3AIAE.
 * Note that not every character gets a legal character after mirroring.
 * In this question, the mirror image of each character is as shown in the figure (blank item means that the character cannot get a legal character after mirror image).
Each input line contains a string (guarantee only the above characters. No blank characters), judge whether it is a palindrome or a mirror string (4 combinations in total). A blank line is output after each set of data.


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.
 */
public class palindrome {
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); 
}
}


}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325746164&siteId=291194637