Advertisement
Guest User

helpmefff

a guest
Sep 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stack>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string st;
  9.     cin >> st;
  10.     stack <int> pool;
  11.     int g = (int) st.size();
  12.     for (int i=0 ; i<g ; i=i+1) {
  13.         if (st[i]='(') {
  14.             pool.push(1);
  15.         }
  16.         else if (st[i]='[') {
  17.             pool.push(2);
  18.         }
  19.         else if (st[i]='{') {
  20.             pool.push(3);
  21.         }
  22.         else if ((st[i]==')')&&(pool.top()=='1')) {
  23.             pool.pop();
  24.         }
  25.         else if ((st[i]==']')&&(pool.top()=='2')) {
  26.             pool.pop();
  27.         }
  28.         else if ((st[i]=='}')&&(pool.top()=='3')) {
  29.             pool.pop();
  30.         }
  31.         else {
  32.             printf("NOo");
  33.             break;
  34.         }
  35.          printf("%d", pool.top());
  36.          printf("%d", pool.size());
  37.     }
  38.     if (pool.size()!=0) {
  39.         printf("NO");
  40.     }
  41.     else{
  42.         printf("YES");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement