题目要求为判断回文串和镜像串,所谓回文串指的就是正读反读字母序列一致的字符串,而所谓镜像串,指的就是对字符串做镜像对称后和原串一致
ASE35A
其反序为
A53ESA
原串的镜像为
ASE35A可知其为一个非回文但却是镜像串的字符串。
对镜像串而言,不可能存在非镜像字符
故
#include "stdio.h"
#include "string.h"char xz(char c)
{
if(c=='E') c='3';
else if(c=='J') c='L';
else if(c=='L') c='J';
else if(c=='S') c='2';
else if(c=='Z') c='5';
else if(c=='2') c='S';
else if(c=='3') c='E';
else if(c=='J') c='L';
else if(c=='A') c='A';
else if(c=='H') c='H';
else if(c=='I') c='I';
else if(c=='M') c='M';
else if(c=='O') c='O';
else if(c=='T') c='T';
else if(c=='U') c='U';
else if(c=='V') c='V';
else if(c=='W') c='W';
else if(c=='X') c='X';
else if(c=='Y') c='Y';
else if(c=='1') c='1';
else if(c=='8') c='8';
else if(c=='5') c='Z';
else if(c=='Z') c='5';
else c='&';//此处应该注意非镜像字符并非不处理
return c;
}//没错我就是神经病写了20多if-else的
int main()
{
int len,i;
char a[100],b[100],c[100];
bool flag1,flag2;
freopen("out.txt","w",stdout);
while(scanf("%s",a)!=EOF)//此处应注意不能用gets(a),输入数据未必规范,可能在行末有空格
{
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
flag1=flag2=0;
len=strlen(a);
for(i=0;i<len;i++)
b[len-1-i]=a[i];
//puts(b);
for(i=0;i<len;i++)
c[i]=xz(b[i]);
//puts(c);
if(strcmp(a,b)==0) flag1=1;
if(strcmp(a,c)==0) flag2=1;
if(flag1==0&&flag2==0) printf("%s -- is not a palindrome.\n", a);
if(flag1==1&&flag2==0) printf("%s -- is a regular palindrome.\n", a);
if(flag1==0&&flag2==1) printf("%s -- is a mirrored string.\n", a);
if(flag1==1&&flag2==1) printf("%s -- is a mirrored palindrome.\n", a);
memset(a,0,sizeof(a));
puts("");注意要换行!!!
fflush(stdin);//清除缓存区排除行位空格回车干扰
}
return 0;
}