代码:
#include<iostream>
#include<string>
using namespace std;
char z(char c)
{
char s = c;
switch (c)
{
case 'E':
s = '3';
break;
case 'J':
s = 'L';
break;
case 'L':
s = 'J';
break;
case 'S':
s = '2';
break;
case 'Z':
s = '5';
break;
case '2':
s = 'S';
break;
case '3':
s = 'E';
break;
case '5':
s = 'Z';
break;
}
return s;
}
bool judge(char c)
{
if (c == 'A' || c == 'H' || c == 'I' || c == 'M' || c == 'O' || c == 'T' || c == 'U' || c == 'V' || c == 'W' || c == 'X' || c == 'Y' || c == '1' || c == '8')
{
return true;
}
else
{
return false;
}
}
int main()
{
string str;
while (cin >> str)
{
int len = str.length();
int blen = len / 2;
int rp = 0, ms = 0, mp = 0, is = 0;
for (int i = 0, j = len - 1; i < blen; ++i, --j)
{
if (str[i] == str[j])
{
if (!(judge(str[i]) && judge(str[j])))
{
ms = 1;
}
continue;
}
else if (str[i] == z(str[j]))
{
rp = 1;
}
else
{
is = 1;
cout << str << " -- is not a palindrome.\n\n";
break;
}
}
if (is)
{
continue;
}
if (rp == 1)
{
if (len % 2)
{
if (judge(str[blen]))
{
cout << str << " -- is a mirrored string.\n\n";
}
else
{
cout << str << " -- is not a palindrome.\n\n";
}
}
else
{
cout << str << " -- is a mirrored string.\n\n";
}
}
else
{
if (!ms)
{
if (len % 2)
{
if (judge(str[blen]))
{
cout << str << " -- is a mirrored palindrome.\n\n";
}
else
{
cout << str << " -- is a regular palindrome.\n\n";
}
}
else
{
cout << str << " -- is a mirrored palindrome.\n\n";
}
}
else
{
cout << str << " -- is a regular palindrome.\n\n";
}
}
}
return 0;
}