Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <stack>
- #include <iostream>
- int main(){
- //considering input as valid parentheses
- std::string inp;
- std::cin >> inp;
- std::stack<bool> st;
- for(uint64_t idx = 0; idx < inp.size(); idx++){
- if (inp[idx] == '(') st.push(true);
- if ( inp[idx] == ')' && ( st.empty() || !st.top() ) ) { std::cout << "NOT OK"; exit(0);}
- if (inp[idx] == ')' && st.top()) st.pop();
- if (inp[idx] == '{') st.push(false);
- if ( inp[idx] == '}' && ( st.empty() || st.top() ) ) { std::cout << "NOT OK"; exit(0);}
- if (inp[idx] == '}' && !st.top()) st.pop();
- }
- std::cout << (st.empty() ? "OK": "NOT OK");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement