401 - Palindromes

Problem Link

import java.util.*;
public class uva401 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
String pal = "";
while(scn.hasNext()) {
pal = scn.next();
int y = pal.length()-1;
int x,z=0,w=0;
int mid = (pal.length()/2) +1;
for(x=0;x<mid;x++) {
if(z==0) {
char a = pal.charAt(x);
char b = pal.charAt(y-x);
if(a == b)
z=0;
else
z=1;
}
else
break;
}
for(x=0;x<mid;x++) {
if(w==0) {
char a = pal.charAt(x);
char b = pal.charAt(y-x);
if(a=='E'){
if(b=='3')
w=0;
else
w=1;
}
else if(a=='3'){
if(b=='E')
w=0;
else
w=1;
}
else if(a=='S'){
if(b=='2')
w=0;
else
w=1;
}
else if(a=='2'){
if(b=='S')
w=0;
else
w=1;
}
else if(a=='Z'){
if(b=='5')
w=0;
else
w=1;
}
else if(a=='5'){
if(b=='Z')
w=0;
else
w=1;
}
else if(a=='J'){
if(b=='L')
w=0;
else
w=1;
}
else if(a=='L'){
if(b=='J')
w=0;
else
w=1;
}
else if(a=='A'){
if(b=='A')
w=0;
else
w=1;
}
else if(a=='Y'){
if(b=='Y')
w=0;
else
w=1;
}
else if(a=='M'){
if(b=='M')
w=0;
else
w=1;
}
else if(a=='O'){
if(b=='O')
w=0;
else
w=1;
}
else if(a=='T'){
if(b=='T')
w=0;
else
w=1;
}
else if(a=='U'){
if(b=='U')
w=0;
else
w=1;
}
else if(a=='V'){
if(b=='V')
w=0;
else
w=1;
}
else if(a=='W'){
if(b=='W')
w=0;
else
w=1;
}
else if(a=='1'){
if(b=='1')
w=0;
else
w=1;
}
else if(a=='8'){
if(b=='8')
w=0;
else
w=1;
}
else if(a=='X'){
if(b=='X')
w=0;
else
w=1;
}
else if(a=='H'){
if(b=='H')
w=0;
else
w=1;
}
else if(a=='I'){
if(b=='I')
w=0;
else
w=1;
}
else if (a=='0') {
w=1;
}
else
w=1;
}
else
break;
}
if(z==1 && w==1)
System.out.println(pal +" -- is not a palindrome.");
else if(z==0 && w==1)
System.out.println(pal +" -- is a regular palindrome.");
else if(z==1 && w==0)
System.out.println(pal +" -- is a mirrored string.");
else if(z==0 && w==0)
System.out.println(pal +" -- is a mirrored palindrome.");
System.out.println("");
}
}
}

Share this

Related Posts

Previous
Next Post »