样例过了,但是 WA
查看原帖
样例过了,但是 WA
726139
残阳如血楼主2024/5/18 14:47
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>

std::unordered_map<char, char> map = {
	{'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'}, {'3', 'E'}, {'5', 'Z'}, {'8', '8'}
};

void mirror(std::string &s) { // 变为镜像串
	for (auto &c : s) {
		if (map.find(c) == map.end()) { s = ""; return ; }
		c = map[c];
	}
}

int main() {
	std::cin.tie(0)->sync_with_stdio(0);
	std::string str;
	while (std::cin >> str) {
		std::string s1 = str, s2 = str, s3 = str;
		std::reverse(s1.begin(), s1.end());
		std::reverse(s3.begin(), s3.end());
		mirror(s2), mirror(s3);
		if (s2 != "") { // 镜像串
			if (s2 == s3) std::cout << str << " -- is a mirrored palindrome.\n\n";
			else std::cout << str << " -- is a mirrored string.\n\n";
		} else {
			if (s1 == str) std::cout << str << " -- is a regular palindrome.\n\n";
			else std::cout << str << " -- is not a palindrome.\n\n";
		}
	}
	std::cout.flush();
	return 0;
}
2024/5/18 14:47
加载中...