Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stack>
- using namespace std;
- int main() {
- string expression;
- stack<bool> l;
- cin >> expression;
- for (char c : expression) {
- if (c == '(') l.push(true);
- else if (c == ')') {
- if (l.empty()) {
- cout << "INVALID" << endl;
- return 0;
- }
- l.pop();
- }
- }
- if (l.size() != 0)
- cout << "INVALID" << endl;
- else
- cout << "OK" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement