#include #include #include #include bool readAndDelete(std::stack& st, std::string& word) { std::queue backlog; int index = 0; while (!st.empty()) { if (st.top() == word[index]) index++; else backlog.push(st.top()); st.pop(); } while (!backlog.empty()) { st.push(backlog.front()); backlog.pop(); } return index == word.length(); } void printStack(std::stack& st) { // Знам че принтирането е в обратен ред, бързам! while (!st.empty()) { std::cout << st.top() << std::endl; st.pop(); } std::cout << std::endl; } int main() { std::string word1 = "mom"; std::stack st1; st1.push('m'); st1.push('o'); st1.push('o'); st1.push('f'); st1.push('m'); std::cout << readAndDelete(st1, word1) << std::endl; printStack(st1); std::string word2 = "car"; std::stack st2; st2.push('y'); st2.push('a'); st2.push('d'); st2.push('c'); st2.push('c'); std::cout << readAndDelete(st2, word2) << std::endl; printStack(st2); }