需要满足的条件是
(1)每个字母是对称的
(2)每个字符串是对称的
#include <iostream> #include <algorithm> #include <string> using namespace std; const string mirrorChar = "AHIMOTUVWXY"; int main(){ string str; cin >> str; bool flag = true; for(int i = 0 ; i < str.length(); ++ i){ if(mirrorChar.find(str[i])==string::npos) { flag = false;break; } } if(flag && str == string(str.rbegin(),str.rend())) cout<<"YES"<<endl; else cout<<"NO"<<endl; }