Determine the mirrored palindrome string

/* 给定一个字符换str(只包含字符'1'-'9'),判断这个字符串是不是镜像回文字符串
   如一个字符串str与它的倒置字符串reverseStr的每一位都是镜像对应,
   那么这个字符串就是镜像回文字符串
   对应关系:
   1 <==> 1
   2 <==> 5
   3 <==> 8
   4 <==> 7
   6 <==> 9
*/

#include <iostream>
#include <vector>
#include <string>
using namespace std;

bool isMirror(string& str) {
    
    
	int len = str.length() - 1;
	int index = 0;
	while (index < len) {
    
    
		switch (str.at(index))
		{
    
    
		case '1':
			if (str.at(len) != '1') {
    
    
				return false;
			}
			break;
		case '2':
			if (str.at(len) != '5') {
    
    
				return false;
			}
			break;
		case '3':
			if (str.at(len) != '8') {
    
    
				return false;
			}
			break;
		case '4':
			if (str.at(len) != '7') {
    
    
				return false;
			}
			break;
		case '5':
			if (str.at(len) != '2') {
    
    
				return false;
			}
			break;
		case '6':
			if (str.at(len) != '9') {
    
    
				return false;
			}
			break;
		case '7':
			if (str.at(len) != '4') {
    
    
				return false;
			}
			break;
		case '8':
			if (str.at(len) != '3') {
    
    
				return false;
			}
			break;
		case '9':
			if (str.at(len) != '6') {
    
    
				return false;
			}
			break;
		default:
			break;
		}
		len--;
		index++;
	}
	return true;
}

void isMirrorPalindrome(vector<string>& strArr) {
    
    
	if (strArr.empty()) {
    
    
		return;
	}
	for (string& str : strArr) {
    
    
		cout << (isMirror(str) ? "YES" : "NO") << endl;
	}
}

int main() {
    
    
	vector<string> strArr{
    
     "69", "6996", "1111" };
	isMirrorPalindrome(strArr);
	system("pause");
	return 0;
}

If there is any infringement, please contact to delete it. If there is an error, please correct me, thank you

Guess you like

Origin blog.csdn.net/xiao_ma_nong_last/article/details/105397574