#include <iostream> #include <string> #include <cstdio> #include <cctype> #pragma warning(disable:4996) using namespace std; string str = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";//镜像串的特征,只有部分字母和数字有镜像 string out[4] = { "啥都不是","是个回文串","是个镜像串","即是回文串,又是镜像串" }; char r(char s) { if (isalpha(s)) return str[s - ‘A‘]; return str[s - ‘0‘ + 25]; } int main() { char a[30]; while (scanf("%s", a) == 1) { int len = strlen(a); int hui = 1, mirror = 1; for (int i = 0;i < (len+1) / 2;++i) { if (a[i] != a[len - i - 1]) hui = 0;//不是回文串 if (r(a[i]) != a[len - i - 1]) mirror = 0;//不是镜像串 } cout << out[mirror * 2 + hui]; } return 0; }
原文:https://www.cnblogs.com/liushipeng648/p/12616396.html