题目大意:输入字符串,字符串类型有四种,1.非镜像非回文;2.镜像非回文;3.回文非镜像;4.回文且镜像。判断输入的字符串为那种类型。(回文:字符串关于中间对称;镜像:字符串关于中间镜像字符对称)
解题思路:用字符数组存下所有的字符及其镜像。判断是否镜像对称就根据字符数组, 需注意,中间字符需有镜像字符才能算镜像。
ac代码:
#include <iostream>
#include <cstring>
using namespace std;
int len, temp, t1, t2;
char st[105];
char a[80] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 8 Z ES15YXWVUT2 O MJ LIH 3 A"};
int main()
{
while (scanf("%s", st)!=EOF){
len = strlen(st);
t1 = t2 = 1;
for (int i=0; i<len/2; i++){
for (int j=0; j<70; j++)
if (a[j] == st[i]){
temp = j;
break;
}
if (st[len-1-i] != a[70-temp-1]){
t1 = 0;
break;
}
}
for (int i=0; i<70; i++)
if (st[len/2] == a[i])
if (a[70-i-1] == ' ')
t1 = 0;
for (int i=0; i<len/2; i++)
if (st[len-1-i] != st[i]){
t2 = 0;
break;
}
if (t1 && t2)
printf("%s -- is a mirrored palindrome.\n\n", st);
else if (t1)
printf("%s -- is a mirrored string.\n\n", st);
else if (t2)
printf("%s -- is a regular palindrome.\n\n", st);
else
printf("%s -- is not a palindrome.\n\n", st);
}
return 0;
}