分析:根据题意,本题需要两个函数is_palidrome()和is_mirrored()来判断字符串。判断是否镜像时,使用两个字符串,其中元素一一对应。
Source:
#include<stdio.h>
#include<string.h>
int is_palindrome(char *s)
{
int i,l=strlen(s);
for(i=0;i<=l-i;i++)
if(s[i]!=s[l-i-1])
return 0;
return 1;
}
int is_mirrored(char *s)
{
int i,j,l=strlen(s);
char s1[22]="AEHIJLMOSTUVWXYZ12358";
char s2[22]="A3HILJMO2TUVWXY51SEZ8";
for(i=0;i<=l-i;i++)
{
for(j=0;j<21;j++)
if(s1[j]==s[i])
break;
if(j==21||s2[j]!=s[l-i-1])
return 0;
}
return 1;
}
int main()
{
char s[21];
int i,l;
while(scanf("%s",s)!=EOF)
{
if(is_palindrome(s))
{
if(is_mirrored(s))
printf("%s -- is a mirrored palindrome.\n\n",s);
else
printf("%s -- is a regular palindrome.\n\n",s);
}
else
{
if(is_mirrored(s))
printf("%s -- is a mirrored string.\n\n",s);
else
printf("%s -- is not a palindrome.\n\n",s);
}
}
return 0;
}