标签:
题目要求:给一个字符串,判断其为回文串,或是镜像串,或是两者都有,或是两者都无。。。。镜像串题目有解释:即一个字符串从左到右读出来和从右到左是一样的。比如“E”和“3”就是可以的。题中附表格。其中说明0和O是一样的,所以将0视为非法字符。
Character | Reverse | Character | Reverse | Character | Reverse |
A | A | M | M | Y | Y |
B | N | Z | 5 | ||
C | O | O | 1 | 1 | |
D | P | 2 | S | ||
E | 3 | Q | 3 | E | |
F | R | 4 | |||
G | S | 2 | 5 | Z | |
H | H | T | T | 6 | |
I | I | U | U | 7 | |
J | L | V | V | 8 | 8 |
K | W | W | 9 | ||
L | J | X | X |
#include<stdio.h> #include<string.h> int check(char a,char b) { if(a==b&&(a=='A'||a=='H'||a=='I'||a=='M'||a=='O'||a=='T'||a=='U' ||a=='U'||a=='V'||a=='W'||a=='X'||a=='Y'||a=='1'||a=='8'))return 1; if((a=='E'&&b=='3')||(a=='3'&&b=='E'))return 1; if((a=='J'&&b=='L')||(a=='L'&&b=='J'))return 1; if((a=='S'&&b=='2')||(a=='2'&&b=='S'))return 1; if((a=='Z'&&b=='5')||(a=='5'&&b=='Z'))return 1; if((a=='0'&&b=='O')||(a=='O'&&b=='0'))return 1; return 0; } int main() { char str[1005]; int l,i,j,k,t1,t2,f,x; while(scanf("%s",str)!=EOF) { t1=t2=f=x=0; l=strlen(str); if(l%2==1)x=1; for(i=0;i<l/2;i++) { if(check(str[i],str[l-1-i])){f=2;t2=1;} else { f=0;break; } } if(f==2){ for(i=0;i<l-1-i;i++) { if(str[i]==str[l-1-i])f=3; else { f=2; break; } } } else { for(i=0;i<l-1-i;i++) { if(str[i]==str[l-i-1])f=1; else { f=0;break; } } } if(l==1){ if(check(str[0],str[0])) printf("%s -- is a mirrored palindrome.\n\n",str); else printf("%s -- is a regular palindrome.\n\n",str); continue; } if(x){ if(f==2){ if(!check(str[l/2],str[l/2]))f=0; } if(f==3){ if(!check(str[l/2],str[l/2]))f=1; } } if(f==0)printf("%s -- is not a palindrome.\n",str); if(f==1)printf("%s -- is a regular palindrome.\n",str); if(f==2)printf("%s -- is a mirrored string.\n",str); if(f==3)printf("%s -- is a mirrored palindrome.\n",str); printf("\n"); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/aaaaacmer/article/details/46779849