401 - Palindromes

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/HackQ_sxj/article/details/88356734
#include <stdio.h>
#include <string.h>
#include <ctype.h>

const char* rev = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char* msg[] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"};

char r(char ch)
{
    if(isalpha(ch))
        return rev[ch-'A'];
    else
        return rev[ch-'0'+25];
}

int main()
{
    char s[30];
    while(scanf("%s", s) != EOF)
    {
        int len = strlen(s);
        int p = 1, m = 1;
        for(int i = 0; i < (len+1/2); i++)
        {
            if(s[i] != s[len-1-i]) p = 0;
            if(s[i] != r(s[len-1-i])) m = 0;
        }
        printf("%s -- is %s.\n\n", s, msg[m*2+p]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/HackQ_sxj/article/details/88356734