#include<stdio.h>
#include<string.h>
#include<ctype.h>
char mirror_Char[26] = {
'A','!','!','!','3','!','!','H','I','L','!','J','M','!','O','!'
,'!','!','2','T','U','V','W','X','Y','5'};
char mirror_Num[9] = {'1','S','E','!','Z','!','!','8','!'};
bool judgeMirror(char* temp)
{
int work = 1;
int length = strlen(temp);
for(int i = 0;i<(length+1)/2;i++)
{
if(isalpha(temp[i]))
{
int pos = temp[i] - 'A';
if(mirror_Char[pos] != temp[length-i-1])
work = 0;
}
else{
int pos = temp[i] - '1';
if(mirror_Num[pos] != temp[length-i-1])
work = 0;
}
if(work == 0) return false;
}
return true;
}
bool judgePalindrome(char *temp)
{
int length = strlen(temp);
int work = 1;
for(int i = 0;i<(length+1)/2;i++)
{
if(temp[i] != temp[length-i-1])
work = 0;
if(work == 0)
return false;
}
return true;
}
char buf[30];
int main()
{
memset(buf, 0, sizeof(buf));
int countJudge = 0;
while(scanf("%s",buf)!=EOF)
{
countJudge = 0;
if(judgeMirror(buf))
{
countJudge += 100;
}
if(judgePalindrome(buf))
{
countJudge += 1000;
}
printf("%s -- ",buf);
if(countJudge == 0)
{
printf("is not a palindrome.\n");
}
if(countJudge == 100)
{
printf("is a mirrored string.\n");
}
if(countJudge == 1000)
{
printf("is a regular palindrome.\n");
}
if(countJudge == 1100)
{
printf("is a mirrored palindrome.\n");
}
memset(buf, 0, sizeof(buf));
printf("\n");
}
return 0;
}
注意:
1.輸入的時候可能包括了換行.
2.符號的對應可能有問題
3.輸出之後還要輸出空行