概述
CF链接:http://codeforces.com/contest/691/problem/B
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
题意:要求对称的回文字符串,我们要知道哪个字母是轴对称的:
A H I M O o T U V v W w x X Y
特殊的还有p,q和b,d注意一下。
#include<iostream>
using namespace std;
int check(char s)
{
if(s=='A'||s=='H'||s=='I'||s=='M'||s=='O'||s=='o')
return 1;
if(s=='T'||s=='U'||s=='V'||s=='v'||s=='W'||s=='w')
return 1;
if(s=='X'||s=='x'||s=='Y')
return 1;
return 0;
}
int main()
{
string s;
cin>>s;
int flag=1;
int len=s.size();
for(int i=0;i<=len/2-1;i++)
{
if(s[i]!=s[len-1-i])
{
if(s[i]=='p'&&s[len-1-i]=='q')
continue;
if(s[i]=='b'&&s[len-1-i]=='d')
continue;
if(s[i]=='q'&&s[len-1-i]=='p')
continue;
if(s[i]=='d'&&s[len-1-i]=='b')
continue;
flag=0;
break;
}
if(check(s[i])==0)
{
flag=0;
break;
}
}
if(len%2==1)
{
if(check(s[len/2])==0)
flag=0;
}
if(flag==1)
cout<<"TAK"<<endl;
else
cout<<"NIE"<<endl;
return 0;
}
/*
A H I
M
O o T U
V v W w x X Y
*/
最后
以上就是害怕鸡翅为你收集整理的B. s-palindrome(模拟)的全部内容,希望文章能够帮你解决B. s-palindrome(模拟)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复