问题描述:
代码展示:
1 #include<stdio.h> 2 #include<string.h> 3 #include<ctype.h> 4 const char* rev="A 3 HIL JM O 2TUVWXY51SE Z 8 ";//注意空格数和非法镜像的个数对应 5 const char* msg[] = {"not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome"}; 6 char r(char ch) 7 { 8 if(isalpha(ch)) 9 return rev[ch-'A']; 10 return rev[ch-'0'+25]; 11 } 12 int main() 13 { 14 char s[30]; 15 while(scanf("%s",s) == 1) 16 { 17 int len = strlen(s); 18 int p = 1,m = 1; 19 for(int i = 0;i<(len+1)/2;i++) 20 { 21 if(s[i] != s[len-1-i]) p=0; 22 if(r(s[i]) != s[len-1-i]) m=0; 23 } 24 printf("%s -- is %s. ",s,msg[m*2+p]); 25 } 26 return 0; 27 } 28 //代码非原创 原文代码链接:https://blog.csdn.net/YeziTong/java/article/details/83899221
运行结果: