📜  是平原 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:52.363000             🧑  作者: Mango

代码示例1
#include 
#include 
bool is_palindrome(const std::string &s){

    if(s.size() == 1 ) return true;
    std::deque d ;
    for(char i : s){
        if(std::isalpha(i)){
           d.emplace_back( toupper(i) );
        }
    }

    auto front = d.begin();
    auto back = d.rbegin();
    while( (front != d.end()) || (back != d.rend())){
        bool ans = (*front == *back);
        if(!ans){
            return ans;
        }
        ++front;++back;
    }

    return true;


}

int main() {
    std::string s = "A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!";
    std::cout << std::boolalpha << is_palindrome(s) << std::endl;
    return 0;
}