#include <iostream>
#include<cctype>
#include<string>
using namespace std;
char mirror(char);
const char mir[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[] = { " -- is not a palindrome."," -- is a regular palindrome.",
" -- is a mirrored string."," -- is a mirrored palindrome." };
int main()
{
string str;
while (cin >> str)
{
int p = 1, m = 1;
int size = str.size();
for (int i = 0; i < (size + 1)/ 2; ++i)//+1是为了确保奇数情况下中间的字符镜像后为合法字符
{
if (str[i] != str[size - 1 - i])
p = 0;
if (str[i] != mirror(str[size - 1 - i]))
m = 0;
}
cout << str << msg[p + m * 2] << endl << endl;
}
}
char mirror(char ch)
{
if (isalpha(ch))
{
return mir[ch - 'A'];
}
else
return mir[ch - '0' + 25];
}
回文词(Palindromes,UVa401)
最新推荐文章于 2024-09-06 10:38:06 发布