Untitled
unknown
c_cpp
a year ago
670 B
7
Indexable
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { stack<char> st; string str; cin >> str; for (char x : str) { if (x == '(' || x == '[') st.push(x); else if (x == ')' && st.top() == '(') st.pop(); else if (x == ']' && st.top() == '[') st.pop(); else st.push(x); } if (st.empty()) cout << "Y"; else cout << "N"; if (i < n - 1) cout << "\n"; } }
Editor is loading...
Leave a Comment