提交时间:2026-06-16 07:03:58

运行 ID: 91786

#include <bits/stdc++.h> using namespace std; void solve() { stack <int> s ; string str ; cin >> str ; for(int i = 0 ; i < str.size() ; i++ ) { if(str[i] == '}') if(s.top == '{') s.pop() ; else{ cout << "NO\n" ; return ; } else if(str[i] == ']') if(s.top == ']') s.pop() ; else{ cout << "NO\n" ; return ; } else if(str[i] == ')') if(s.top == '(') s.pop() ; else{ cout << "NO\n" ; return ; } else if(str[i] == '>') if(s.top == '<') s.pop() ; else{ cout << "NO\n" ; return ; } else s.push(str[i]) ; } cout << "YES\n" ; } int main() { int n ; cin >> n ; while(n--) solve() ; return 0; }