Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. string expression;
  9. stack<bool> l;
  10.  
  11. cin >> expression;
  12.  
  13. for (char c : expression) {
  14. if (c == '(') l.push(true);
  15. else if (c == ')') {
  16. if (l.empty()) {
  17. cout << "INVALID" << endl;
  18. return 0;
  19. }
  20. l.pop();
  21. }
  22. }
  23.  
  24. if (l.size() != 0)
  25. cout << "INVALID" << endl;
  26. else
  27. cout << "OK" << endl;
  28.  
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement