Why my code WA on #1?
查看原帖
Why my code WA on #1?
594203
BartonMeow楼主2022/4/23 15:10

Code:

#include <iostream>
#include <map>
using namespace std;
map<char, char> mirror = {
        {'A', 'A'}, {'E', '3'}, {'H', 'H'}, {'I', 'I'}, {'J', 'L'}, {'L', 'J'}, {'M', 'M'},
        {'O', 'O'}, {'S', '2'}, {'T', 'T'}, {'U', 'U'}, {'V', 'V'}, {'W', 'W'}, {'X', 'X'},
        {'Y', 'Y'}, {'Z', '5'}, {'1', '1'}, {'2', 'S'}, {'5', 'Z'}, {'8', '8'}
    };
bool checkReverse(string s)
{
    int siz = s.size();
    for (int i = 0; i < siz / 2; i++)
        if (s[i] != s[siz - i - 1])
            return false;
    return true;
}
bool checkMirror(string s)
{
    int siz = s.size();
    for (int i = 0; i < siz / 2; i++)
        if (s[i] != mirror[s[siz - i - 1]])
            return false;
    return true;
}
int main()
{
    string str;
    bool cr, cm;
    while (cin >> str)
    {
        cr = checkReverse(str);
        cm = checkMirror(str);
        cout << str << " -- ";
        if (cr && cm) cout << "is a mirrored palindrome.";
        else if (cr && !cm) cout << "is a regular palindrome.";
        else if (!cr && cm) cout << "is a mirrored string.";
        else cout << "is not a palindrome.";
    }
    return 0;
}

Record:

https://www.luogu.com.cn/record/74455609

2022/4/23 15:10
加载中...