Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- int main() {
- std::string input, expected;
- std::stack<char> stack;
- std::cin >> input >> expected;
- size_t iex = 0;
- for(size_t i = 0; i < input.length(); i++) {
- stack.push(input[i]);
- while(!stack.empty() && stack.top() == expected[iex]) {
- stack.pop();
- iex++;
- }
- }
- std::cout << (iex == expected.length() ? "YES\n" : "NO\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement