Advertisement
dreadmachine

stack_test.cpp

Nov 12th, 2021
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4.  
  5. int main() {
  6.     std::string input, expected;
  7.     std::stack<char> stack;
  8.     std::cin >> input >> expected;
  9.     size_t iex = 0;
  10.     for(size_t i = 0; i < input.length(); i++) {
  11.         stack.push(input[i]);
  12.         while(!stack.empty() && stack.top() == expected[iex]) {
  13.             stack.pop();
  14.             iex++;
  15.         }
  16.     }
  17.     std::cout << (iex == expected.length() ? "YES\n" : "NO\n");
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement