Palindromes UVA - 401

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leekerian/article/details/83832773

紫薯-3

读懂题意就可以

#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>

using namespace std;

map<char,char> mp;

char str[11111];
int main()
{
    mp['A']='A';
    mp['E']='3';
    mp['H']='H';
    mp['I']='I';
    mp['J']='L';
    mp['L']='J';
    mp['M']='M';
    mp['O']='O';
    mp['S']='2';
    mp['T']='T';
    mp['U']='U';
    mp['V']='V';
    mp['W']='W';
    mp['X']='X';
    mp['Y']='Y';
    mp['Z']='5';
    mp['1']='1';
    mp['2']='S';
    mp['3']='E';
    mp['5']='Z';
    mp['8']='8';
    while(gets(str))
    {
        for(int i=0;str[i]!='\0';i++)
        {
            printf("%c",str[i]);
        }
        printf(" -- ");
        int l=0;
        int r=strlen(str)-1;
        int cont=0;
        while(l<=r)
        {
            if(str[l]==str[r])
            {
                l++;
                r--;
            }
            else
            {
                cont=1;
                break;
            }
        }
        if(cont)
        {
            int l=0;
            int r=strlen(str)-1;
            int cont3=0;
            while(l<=r)
            {
                if(str[l]!=str[r])
                {
                    if(mp[str[l]]==str[r])
                    {
                        l++;
                        r--;
                    }
                    else
                    {
                        cont3=1;
                        break;
                    }
                }
                else
                {
                    l++;
                    r--;
                }
            }
            if(cont3==0)
            {
                printf("is a mirrored string.\n\n");
            }
            else
            {
                printf("is not a palindrome.\n\n");
            }
        }
        else
        {
            int cont1=0;
            for(int i=0;str[i]!='\0';i++)
            {
                if(mp[str[i]]!=str[i])
                {
                    cont1=1;
                    break;
                }
            }
            if(cont1==0)
            {
                printf("is a mirrored palindrome.\n\n");
            }
            else
            {
                printf("is a regular palindrome.\n\n");
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/leekerian/article/details/83832773