镜像字符

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

思路:把那些镜像的两个字符写出来,然后再去比较就好了
我自己写的

#include<bits/stdc++.h>
using namespace std;
const int maxx=1e4+10;
char a[maxx];
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>a;
    int len=strlen(a);
    long long int sum=0;
    for(int i=0; i<=len/2; i++)//偶数的时候除了每个比较了一次之外还多比较了一次,奇数的时候每个都比较了一次
    {
        if(a[i]=='b'&&a[len-i-1]=='d')
            sum++;
        else if(a[i]=='d'&&a[len-i-1]=='b')
            sum++;
        else if(a[i]=='o'&&a[len-i-1]=='o')
            sum++;
        else if(a[i]=='p'&&a[len-i-1]=='q')
            sum++;
        else if(a[i]=='q'&&a[len-i-1]=='p')
            sum++;
        else if(a[i]=='v'&&a[len-i-1]=='v')
            sum++;
        else if(a[i]=='w'&&a[len-i-1]=='w')
            sum++;
        else if(a[i]=='x'&&a[len-i-1]=='x')
            sum++;
        else if(a[i]=='A'&&a[len-i-1]=='A')
            sum++;
        else if(a[i]=='H'&&a[len-i-1]=='H')
            sum++;
        else if(a[i]=='I'&&a[len-i-1]=='I')
            sum++;
        else if(a[i]=='M'&&a[len-i-1]=='M')
            sum++;
        else if(a[i]=='O'&&a[len-i-1]=='O')
            sum++;
        else if(a[i]=='T'&&a[len-i-1]=='T')
            sum++;
        else if(a[i]=='U'&&a[len-i-1]=='U')
            sum++;
        else if(a[i]=='V'&&a[len-i-1]=='V')
            sum++;
        else if(a[i]=='W'&&a[len-i-1]=='W')
            sum++;
        else if(a[i]=='X'&&a[len-i-1]=='X')
            sum++;
        else if(a[i]=='Y'&&a[len-i-1]=='Y')
            sum++;
    }
    if(sum==(len/2+1))
        cout<<"TAK"<<endl;
    else
        cout<<"NIE"<<endl;
    return 0;
}

学长给我发的,说我写的太麻烦了,没必要那么多if…

#include<bits/stdc++.h>

using namespace std;
string a = "AbdHIMOopqTUVvWwXxY";
string b = "AdbHIMOoqpTUVvWwXxY";

bool check(char A, char B) {
    for (int i = 0; i < a.size(); i++) {
        if (A == a[i] && B == b[i])return true;
    }
    return false;
}

string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (!check(s[i], s[s.size() - i - 1]))return puts("NIE");
    }
    return puts("TAK");
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值