Mahmoud_Hawara

Untitled

Jul 19th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int N = 1e6 + 5;
  7. const int dx[4] = {0, 0, 1, -1};
  8. const int dy[4] = {1, -1, 0, 0};
  9.  
  10. long long t;
  11. string s;
  12.  
  13. int main()
  14. {
  15.     IO
  16.     cin >> t;
  17.     while (t--)
  18.     {
  19.         stack<char>st;
  20.         cin >> s;
  21.         bool ok = 1;
  22.         for (int i = 0; s[i] && ok; i++)
  23.         {
  24.             if (s[i] == '(' || s[i] == '[')
  25.             {
  26.                 st.push(s[i]);
  27.             }
  28.             else if (s[i] == ')')
  29.             {
  30.                 if (st.size() && st.top() == '(')st.pop();
  31.                 else ok = 0;
  32.             }
  33.             else
  34.             {
  35.                 if (st.size() && st.top() == '[')st.pop();
  36.                 else ok = 0;
  37.             }
  38.         }
  39.         if (ok && st.empty())cout << "Yes\n";
  40.         else cout << "No\n";
  41.     }
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment