You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
//输入+输出重定向
|
|
freopen("../1393.in", "r", stdin);
|
|
freopen("../1393.out", "w", stdout);
|
|
|
|
int n;
|
|
cin >> n;
|
|
cin.ignore();//清除一个字符
|
|
//清除缓冲区
|
|
//https://blog.csdn.net/selina8921/article/details/79067941
|
|
string s = "";
|
|
for (int i = 0; i < n; ++i) {
|
|
getline(cin, s);
|
|
stack<char> st;
|
|
bool result = true;
|
|
for (int j = 0; j < s.size(); ++j) {
|
|
if (s[j] == '(' || s[j] == '[' || s[j] == '<' || s[j] == '{') st.push(s[j]);
|
|
if (s[j] == ')') {
|
|
if (!st.empty() && st.top() == '(') st.pop();
|
|
else result = false;
|
|
}
|
|
if (s[j] == ']') {
|
|
if (!st.empty() && st.top() == '[') st.pop();
|
|
else result = false;
|
|
}
|
|
if (s[j] == '>') {
|
|
if (!st.empty() && st.top() == '<') st.pop();
|
|
else result = false;
|
|
}
|
|
if (s[j] == '}') {
|
|
if (!st.empty() && st.top() == '{') st.pop();
|
|
else result = false;
|
|
}
|
|
}
|
|
if (st.empty() && result)cout << "YES" << endl;
|
|
else cout << "NO" << endl;
|
|
}
|
|
|
|
//关闭文件
|
|
fclose(stdin);
|
|
fclose(stdout);
|
|
return 0;
|
|
}
|