Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const long long MOD = 1e9 + 7, OO = 1e18;
- const double PI = acos(-1);
- const int N = 1e6 + 5;
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0, 0};
- long long t;
- string s;
- int main()
- {
- IO
- cin >> t;
- while (t--)
- {
- stack<char>st;
- cin >> s;
- bool ok = 1;
- for (int i = 0; s[i] && ok; i++)
- {
- if (s[i] == '(' || s[i] == '[')
- {
- st.push(s[i]);
- }
- else if (s[i] == ')')
- {
- if (st.size() && st.top() == '(')st.pop();
- else ok = 0;
- }
- else
- {
- if (st.size() && st.top() == '[')st.pop();
- else ok = 0;
- }
- }
- if (ok && st.empty())cout << "Yes\n";
- else cout << "No\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment