需要滿足的條件是
(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; }