7_13_K题 Palindromes
题意
根据题目给出的条件判断一个字符串是否为回文串,镜像串,回文镜像串等
思路
按题意模拟判断就好
代码
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
char chart[] = {'A',' ',' ',' ','3',' ',
' ','H','I','L',' ','J',
'M',' ','O',' ',' ',' ',
'2','T','U','V','W','X',
'Y','5'};
char num[] = {'0','1','S','E',' ','Z',' ',' ','8',' '};
const int maxn = 25;
char str[maxn];
bool pali(){
int len = strlen(str);
for(int i = 0,j = len-1; i < j; i++,j--){
if((str[i] == '0' && str[j] == 'O')
|| (str[i] == 'O' && str[j] == '0'))
continue;
if(str[i] != str[j]) return false;
}
return true;
}
bool morr(){
char temp[maxn];
int len = strlen(str);
for(int i = 0,j = len-1; i < len;i++,j--){
if(isalpha(str[i]))
temp[i] = chart[str[i] - 'A'];
else
temp[i] = num[str[i] - '0'];
if((temp[i] == '0' && str[j] == 'O')
|| (temp[i] == 'O' && str[j] == '0'))
continue;
if(temp[i] != str[j])
return false;
}
return true;
}
int main(){
while(~scanf("%s",str)){
bool m = morr();
bool p = pali();
if(m && p) printf("%s -- is a mirrored palindrome.\n",str);
if(!m && p) printf("%s -- is a regular palindrome.\n",str);
if(m && !p) printf("%s -- is a mirrored string.\n",str);
if(!m && !p) printf("%s -- is not a palindrome.\n",str);
puts("");
}
return 0;
}