判断一个字符串是不是镜像串和回文串
下表是题目所给的对称字符。
输入格式:输入多组数据,每行一个字符串
输出格式:”字符串—是否是回文串,镜像串,回文镜像串."
输入样例:
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
输出样例:
NOTAPALINDROME -- is not a palindrome.
ISAPALINILAPASI -- is a regular palindrome.
2A3MEAS -- is a mirrored string.
ATOYOTA -- is a mirrored palindrome.
直接打表,列举情况就可以
#include<stdio.h>
#include<string.h>
int main()
{
char save[200],a[200];
int i,j;
int flag1=1,flag2=1;
memset(save,0,sizeof(save));
save['A']='A';
save['E']='3';
save['H']='H';
save['I']='I';
save['J']='L';
save['L']='J';
save['M']='M';
save['O']='O';
save['S']='2';
save['T']='T';
save['U']='U';
save['V']='V';
save['W']='W';
save['X']='X';
save['Y']='Y';
save['Z']='5';
save['2']='S';
save['1']='1';
save['3']='E';
save['5']='Z';
save['8']='8';
while(scanf("%s",a)!=EOF)
{
flag1=1;
flag2=1;
i=strlen(a);
for(j=0;j<=(i+1)/2-1;j++)
{
if(a[j]!=a[i-j-1])
flag1=0;
if(a[j]!=save[a[i-j-1]])
flag2=0;
}
if(flag1)
{
if(flag2)
printf("%s -- is a mirrored palindrome.\n",a);
else
printf("%s -- is a regular palindrome.\n",a);
}
else if(flag2)
printf("%s -- is a mirrored string.\n",a);
else
printf("%s -- is not a palindrome.\n",a);
printf("\n");
}
return 0;
}