fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. template<typename T>
  9. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  10. // order_of_key -----> return index
  11. // find_by_order ----> use index
  12.  
  13. #define ll long long
  14. #define ull unsigned long long
  15. #define ld long double
  16. #define dl double
  17. #define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  18. #define f first
  19. #define s second
  20. #define pb push_back
  21. #define el '\n'
  22. #define INF 0x3f3f3f3f3f3f3f3f
  23. #define flag(x) cout << x << '\n';
  24. #define all(x) x.begin(),x.end()
  25. #define allr(x) x.rbegin(),x.rend()
  26. #define ones(x) __builtin_popcountll(x)
  27. #define point complex <double>
  28. #define memss(a, b, sz) memset(arr,b,sz * sizeof (arr[0]))
  29.  
  30.  
  31. int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
  32. int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
  33.  
  34. const int mod = 1e9 + 7, N = 1e3 + 100, mod2 = 998244353, M = 1e7;
  35. const ld eps = 1e-9;
  36.  
  37. void set_ans(int Case) {
  38. string s;
  39. getline(cin,s);
  40. stack<char>st;
  41. for(auto i : s) {
  42. if(i == '(') st.push(i);
  43. else if(i == ')' and !st.empty() and st.top() == '(') st.pop();
  44. else if(i == '[') st.push(i);
  45. else if(i == ']' and !st.empty() and st.top() == '[') st.pop();
  46. else {
  47. return void (cout << "No\n");
  48. }
  49. }
  50. cout << (st.empty() ? "Yes\n" : "No\n");
  51. }
  52. int main() {
  53. io
  54. #ifndef ONLINE_JUDGE
  55. freopen("input.txt", "rt", stdin);
  56. freopen("output.txt", "wt", stdout);
  57. #endif
  58. int t = 1;
  59. cin >> t;
  60. cin.ignore();
  61. for (int Case = 1; Case <= t; Case++)
  62. set_ans(Case);
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5512KB
stdin
Standard input is empty
stdout
Yes