40 Palindromes

Problem Link: 401 – Palindromes

 

 

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a,b;

    while(cin >> a){

        b=a;
        reverse(b.begin(),b.end());

        int x=0,y=0;

        if(b==a)
            x=1;

        for(int i=0;b[i]!='\0';i++){

            if(b[i]=='A')
                b[i]='A';
            else if(b[i]=='E')
                b[i]='3';
            else if(b[i]=='H')
                b[i]='H';
            else if(b[i]=='I')
                b[i]='I';
            else if(b[i]=='J')
                b[i]='L';
            else if(b[i]=='L')
                b[i]='J';
            else if(b[i]=='M')
                b[i]='M';
            else if(b[i]=='O')
                b[i]='O';
            else if(b[i]=='S')
                b[i]='2';
            else if(b[i]=='T')
                b[i]='T';
            else if(b[i]=='U')
                b[i]='U';
            else if(b[i]=='V')
                b[i]='V';
            else if(b[i]=='W')
                b[i]='W';
            else if(b[i]=='X')
                b[i]='X';
            else if(b[i]=='Y')
                b[i]='Y';
            else if(b[i]=='Z')
                b[i]='5';
            else if(b[i]=='1')
                b[i]='1';
            else if(b[i]=='2')
                b[i]='S';
            else if(b[i]=='3')
                b[i]='E';
            else if(b[i]=='5')
                b[i]='Z';
            else if(b[i]=='8')
                b[i]='8';
            else
				b[i]=32;
        }

        if(b==a)
            y=1;
        cout << a ;
        if(x==0 && y==0)
            printf(" -- is not a palindrome.\n");
        else if(x==1 && y==0)
            printf(" -- is a regular palindrome.\n");
        else if(x==0 && y==1)
            printf(" -- is a mirrored string.\n");
        else if(x==1 && y==1)
            printf(" -- is a mirrored palindrome.\n");

		printf("\n");

    }

    return 0;
}

Advertisements