Pearlo's Espionage: Cracking the Symmetric Password

In the whimsical world of Potatoland, a secret base holds the recipe for the most delicious potato mash. Our intrepid secret agent, Pearlo, from the neighboring land of Porridgia, has been trained for years to infiltrate this base and steal the recipe for his homeland. Now, standing before the base's entrance, Pearlo faces a formidable challenge: a combination lock.

The lock's terminal is a 3x3 square digital keyboard with digits from 1 to 9. The password, known to consist of distinct digits, is suspected to be symmetric around the central button. Pearlo, armed with a heat sensor, can detect which buttons were pressed by the previous worker. To narrow down the possible password combinations, Pearlo needs your help to determine if the password is indeed symmetric.

The Task

Your mission is to write a program that analyzes the pressed buttons on the keypad and determines if the password is symmetric with respect to the central button.

Input

The input is a 3x3 matrix representing the keypad. Each cell contains either an 'X', indicating a pressed button, or a '.', indicating an unpressed button. The matrix may contain no 'X', or it may contain no '.'.

Output

Print 'YES' if the password is symmetric with respect to the central button, and 'NO' otherwise.

Example Input:

X.. 
.X. 
..X

Example Output:

YES

C++ Implementation:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool isSymmetric(vector<string>& matrix) {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (matrix[i][j] != matrix[2 - i][2 - j]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    vector<string> matrix(3);
    for (int i = 0; i < 3; i++) {
        cin >> matrix[i];
    }
    
    if (isSymmetric(matrix)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

Challenge: Can you optimize this code to improve its efficiency?

This intriguing problem offers a glimpse into the world of espionage, code-breaking, and the power of pattern recognition. Good luck, Agent Pearlo! Let's crack this password and secure that recipe for Porridgia!

Pearlo's Espionage: Cracking the Symmetric Password

原文地址: https://www.cveoy.top/t/topic/pRDj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录