ZeroJudge M801: Mirroring

After waking up, you found yourself locked in a room, and upon looking around, you noticed that the walls were covered with strings of uppercase English letters. From a corner, you found a piece of paper indicating that the key to escaping the room was to first find all the mirror-symmetrical strings on the wall.

Here, the term "mirror symmetry" refers to two conditions that must be met:

  1. The string is a palindrome, meaning that it reads the same from left to right as it does from right to left.
  2. The string contains only the letters AHIMOTUVWXY.

Please write a program to determine whether a string is a mirrored palindrome.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input data consists of a single line containing a string. The length of the string is N (1 ≤ N < 1000). The string contains only uppercase English letters.Output a string "Yes" or "No," indicating whether the input string is a mirrored palindrome.
AYes
ABANo
HOHOHYes

    Thought Process

    You can use the "EOF" approach to receive the input character by character, and use a Map or an If statement to determine whether each character is one of "AHIMOTUVWXY." It's essential to note that even if a character is not among "AHIMOTUVWXY," you still need to finish reading the data before outputting "No." You can use a boolean variable to track whether it's possible to output "No" immediately. If a character belongs to "AHIMOTUVWXY," you can append it to a String variable and check for palindrome after EOF. You can determine if it's a palindrome by using the "Reverse" function to compare whether the string from right to left is the same as the string from left to right.

    Sample Code-ZeroJudge M801: Mirroring

    #include <iostream>
    #include <map>
    #include <algorithm>
    using namespace std;
    
    int main() {
        cin.sync_with_stdio(0);
        cin.tie(0);
        char ch;
        string str = "";
        map<char, int>MAP;
        MAP['A'] = 1;
        MAP['H'] = 1;
        MAP['I'] = 1;
        MAP['M'] = 1;
        MAP['O'] = 1;
        MAP['T'] = 1;
        MAP['U'] = 1;
        MAP['V'] = 1;
        MAP['W'] = 1;
        MAP['X'] = 1;
        MAP['Y'] = 1;
        bool stop = false;
        while (cin >> ch)
        {
            if (MAP[ch] == 1) str += ch;
            else stop = true;
        }
        if (stop) cout << "No\n";
        else
        {
            string tmp = str;
            reverse(tmp.begin(), tmp.end());
            if (tmp == str) cout << "Yes\n";
            else cout << "No\n";
        }
    }
    
    //ZeroJudge M801
    //Dr. SeanXD

    Comments