You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.0 KiB

2 years ago
#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;
}