//Notes: 1、每个结果最后有2个\n\n 2、‘A‘->‘A‘ ‘B‘->‘ ‘ ‘E‘->‘3‘ 3、0与O要一样
#include <iostream> using namespace std; #include <cstdio> #include <string> #include <cstring> #include <cctype> string str0 = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; string str1 = "_A 3 HIL JM O 2TUVWXY51SE Z 8 0"; //»ØÎÄpalindrome bool isPalindromeString(string str){ for(int i = 0, len = str.length(); i <= len/2; i++) if(str[i] != str[len-i-1]) return 0; return 1; } bool isMirroedString(string str){ for(int i = 0, len = str.length(); i <= len/2; i++){ if((str[i] == ‘0‘ && str[len-1-i]==‘O‘) || (str[i] == ‘O‘ && str[len-i-1]==‘0‘)) continue; else if(str1[str0.find(str[i])] != str[len-i-1]) return 0; } return 1; } int main(){ //freopen("data.in", "r", stdin); string string; while(cin >> string){ if(isMirroedString(string)){ if(isPalindromeString(string)) cout << string << " -- is a mirrored palindrome."; else cout << string << " -- is a mirrored string."; }else{ if(isPalindromeString(string)) cout << string << " -- is a regular palindrome."; else cout << string << " -- is not a palindrome."; } cout << "\n\n"; } return 0; }
时间: 2024-10-10 18:29:59