回文串是反转后与原串相同,镜像串是左右镜像后和原串相同。
#include<stdio.h>
#include<string.h>
#define maxn 50
const char nor[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
const char rev[]="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(){
char s[maxn]={'\0'};
int i,hw,jx,length;
while(scanf("%s",s)!=EOF){
hw=1;jx=1;
length=strlen(s);
for(i=0;i<length/2;i++){
if(hw==1&&s[i]!=s[length-i-1]) hw=0;
if(jx==1&&s[length-i-1]!=rev[strchr(nor,s[i])-nor]) jx=0;
}
printf("%s -- %s\n\n",s,msg[jx*2+hw]); //这种方法要简单得多
// if(!hw&&!jx) printf("%s -- %s\n\n",s,msg[0]);
// else if(hw&&!jx) printf("%s -- %s\n\n",s,msg[1]);
// else if(!hw&&jx) printf("%s -- %s\n\n",s,msg[2]);
// else if(hw&&jx) printf("%s -- %s\n\n",s,msg[3]);
}
return 0;
}