Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <stack>
  3. #include <string>
  4. #include <stdio.h>
  5. #include <set>
  6. #include <cstdio>
  7. using namespace std;
  8.  
  9. #include <cstdio>
  10. using namespace std;
  11. int main() {
  12.     char ch;
  13.     stack<char> myStack;
  14.     while (scanf("%c", &ch)) {
  15.         if ((ch == '(') || (ch == '[') || (ch == '{')) {
  16.             myStack.push(ch);
  17.         } else if (ch == ')') {
  18.             if ((myStack.size() == 0) || (myStack.top() != '(')) {
  19.                 cout << "no" << endl;
  20.                 return 0;
  21.             } else {
  22.                 myStack.pop();
  23.             }
  24.         } else if (ch == ']') {
  25.             if ((myStack.size() == 0) || (myStack.top() != '[')) {
  26.                 cout << "no" << endl;
  27.                 return 0;
  28.             } else {
  29.                 myStack.pop();
  30.             }
  31.         } else if (ch == '}') {
  32.             if ((myStack.size() == 0) || (myStack.top() != '{')) {
  33.                 cout << "no" << endl;
  34.                 return 0;
  35.             } else {
  36.                 myStack.pop();
  37.             }
  38.         }
  39.     }
  40.  
  41.     if (myStack.size() == 0) {
  42.         cout << "yes" << endl;
  43.     } else {}
  44.         cout << "no" << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement