Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
English alphabet
You are given a string s. Check if the string is "s-palindrome".
Input
The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.
Output
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
Examples
Input
oXoxoXo
Output
TAK
Input
bod
Output
TAK
Input
ER
Output
NIE
这里要注意的是,p要和q对应,b要和d对应,其余的就必须是自己就对称的字母
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
char p[15]={'A','H','I','M','O','o','T','U','V','v','W','w','X','x','Y'};
bool f(char x){//看看在不在p数组里
for(int i=0;i<15;i++){
if(x==p[i])
return true;
}
return false;
}
int main(){
string str;
cin>>str;
int len=str.length() ;
bool flag=true;
for(int i=0;i<=len/2;i++){
if(str[i]==str[len-i-1]){//两个字符相等
if(!f(str[i]))
flag=false;
}
else{
if((str[i]=='p'&&str[len-i-1]=='q')||(str[i]=='q'&&str[len-i-1]=='p'));
else if((str[i]=='b'&&str[len-i-1]=='d')||(str[i]=='d'&&str[len-i-1]=='b'));
else flag=false;
}
}
if(flag)
cout<<"TAK"<<endl;
else
cout<<"NIE" <<endl;
return 0;
}
本文介绍了一种特殊的回文字符串,即s-palindrome,并提供了一个算法来检查给定的字符串是否符合这种特殊回文的标准。s-palindrome要求字符串关于中间对称,且特定的字符对(如p-q, b-d)或自身对称的字符(如A, H, I等)才能构成有效的回文。
&spm=1001.2101.3001.5002&articleId=88416094&d=1&t=3&u=19facfc67576449e8b41267bce0d9a99)
462

被折叠的 条评论
为什么被折叠?



