Từ Trường THPT Chuyên Chu Văn An, Hà Nội
Thông tin
**#include <bits/stdc++.h>
using namespace std;
define ll long long
define endl '\n'
int n; string s; stack <char> st;
int main() {
ios_base::sync_with_stdio (false);
cin.tie (0) ; cout.tie (0);
freopen("NGOACDUNG.INP" , "r" , stdin);
freopen("NGOACDUNG.OUT" , "w" , stdout);
cin>>n;
for (int i=1 ; i<=n ; i++)
{
while(!st.empty()) st.pop();
cin>>s;
for (int i=0 ; i<=s.length()-1 ; i++)
{
if (s[i]=='(' || s[i]=='[' || s[i]=='{') st.push(s[i]);
else
{
if (s[i]==')')
{
if (st.top()=='(') st.pop();
else break;
}
else if (s[i]==']')
{
if (st.top()=='[') st.pop();
else break;
}
else if (s[i]=='}')
{
if (st.top()=='{') st.pop();
else break;
}
}
}
if (st.empty()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
} **