Files
python/RuMenJingDian/LiTi/P_3_3.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

32 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const char *rev = "A 3 HILJM 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'];//如果是字符那么计算出它所在的索引号比如是A那么索引号是0
else return rev[ch - '0' + 25]; //如果是数字,那么-'0'就是0+25就是数字对应的索引号
}
int main() {
ios::sync_with_stdio(false); //读入输出优化的强迫症
char s[30];
while (scanf("%s", s) == 1) {
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 (r(s[i]) != s[len - 1 - i]) m = 0;
}
//这个msg的数组索引用的好有点二进制的意思~
printf("%s-- is %s.\n\n", s, msg[m * 2 + p]);
}
return 0;
}