📜  std::stack - C++ 代码示例

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

代码示例1
#include 
#include 
#include 
#include 
#include 
bool is_palindrome(const std::string &s){
    std::stack LIFO;
    std::queue FIFO;
    for(auto &c: s){
        if(std::isalpha(c)){

            LIFO.push(std::toupper(c));
            FIFO.push(std::toupper(c));
        }
    }
    bool ans;
    while( (LIFO.size() && FIFO.size()) != 0){
        ans = (LIFO.top() == FIFO.front());
        if(!ans){
            return ans;
        }
        LIFO.pop(),FIFO.pop();
    }
    return true ;
}



int main() {
    try{
        std::string s ;
        std::cout << "Enter a string" << std::endl;
        std::cin >> s;
        std::cout << std::boolalpha << is_palindrome( s) << std::endl;
    }catch(std::exception &e){
     std::cout << e.what() << std::endl;
    }

    return 0;
}