Advertisement
EWTD

Pre-View#4B

Nov 10th, 2022 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <string>
  2. #include <stack>
  3. #include <iostream>
  4.  
  5. int main(){
  6. //considering input as valid parentheses
  7. std::string inp;
  8. std::cin >> inp;
  9. std::stack<bool> st;
  10. for(uint64_t idx = 0; idx < inp.size(); idx++){
  11. if (inp[idx] == '(') st.push(true);
  12. if ( inp[idx] == ')' && ( st.empty() || !st.top() ) ) { std::cout << "NOT OK"; exit(0);}
  13. if (inp[idx] == ')' && st.top()) st.pop();
  14. if (inp[idx] == '{') st.push(false);
  15. if ( inp[idx] == '}' && ( st.empty() || st.top() ) ) { std::cout << "NOT OK"; exit(0);}
  16. if (inp[idx] == '}' && !st.top()) st.pop();
  17. }
  18. std::cout << (st.empty() ? "OK": "NOT OK");
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement