#include<stdio.h>
#include<string.h>
using namespace std;
const char s[]="A 3 HIL JM O 2TUVWXY51SE Z 8 ";
char a[30];
char Mirror(char x){
if(x>='A'&&x<='Z')
return s[x-'A'];
else
return s[x-'0'+26];
}
int main(){
bool flag1=true,flag2=true;
while(scanf("%s",a)==1){
flag1=true; flag2=true;
int n=strlen(a);
int i=0,j=n-1;
while(i<j){
if(a[i]!=a[j])
flag1=false;
if(Mirror(a[j])!=a[i])
flag2=false;
i++; j--;
}
if(flag1 && flag2)
printf("%s -- is a mirrored palindrome.\n",a);
else if(flag1 && !flag2)
printf("%s -- is a regular palindrome.\n",a);
else if(!flag1 && flag2)
printf("%s -- is a mirrored string.\n",a);
else
printf("%s -- is not a palindrome.\n",a);
}
return 0;
}
【算法竞赛入门经典】 程序3-7 回文词
最新推荐文章于 2022-01-11 14:10:33 发布