镜像串,即像镜子一样的串。
这个是对照表。
如何简洁明了的写出程序,找出对应的镜像呢?初始时我们肯定会想一个一个的找,这样虽然可以建立起联系,但是太过于麻烦,使用字符串常量存储是很明智的选择。
附上代码
#include<stdio.h>
#include<string.h>
int main()
{
char a[]="AEHIJLMOSTUVWXYZ12358";
char b[]="A3HILJMO2TUVWXYZ1SEZ8";
char c[100];
int len,i,j;
scanf("%s",c);
j=0;
for(i=0;i<strlen(a)&&j<=strlen(c)/2;i++)
{
if(c[j]==a[i])
{
if(c[strlen(c)-j-1]!=b[i])
break;
else
{
j++;
i=0;
}
}
}
if(j!=strlen(c)/2+1)
printf("%s--is not a mirrored string",c);
else printf("%s--is a mirrored string",c);
}