标签:
#include <stdio.h>
#include <string.h>
char mirror(char c)
{
static const char m[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
if (‘A‘ <= c && c <= ‘Z‘)
return m[c-‘A‘];
else
return m[c-‘1‘+26];
}
int main()
{
static const char* msg[] = { "not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome" };
char str[30];
size_t i, j, p, m, len, hafLen;
while (scanf("%s", str) == 1)
{
p = 1, m = 2;
len = strlen(str);
hafLen = (len+1)/2;
for (i = 0; i < hafLen; ++i)
{
j = len-i-1;
if (p && (str[i] != str[j]))
p = 0;
if (m && (str[i] != mirror(str[j])))
m = 0;
if (!p && !m)
break;
}
printf("%s -- is %s.\n\n", str, msg[p+m]);
}
}
标签:
原文地址:http://www.cnblogs.com/danny1221/p/4590491.html