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.
40 lines
789 B
40 lines
789 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
stack<char> s;
|
|
int nums;
|
|
|
|
/**
|
|
测试用例:
|
|
2
|
|
[({})]
|
|
()[]()
|
|
*/
|
|
char trans(char a) {
|
|
if (a == ')') return '(';
|
|
if (a == ']') return '[';
|
|
if (a == '}') return '{';
|
|
return '\0';
|
|
}
|
|
|
|
int main() {
|
|
cin >> num;
|
|
string p;
|
|
//getline(cin, p);//读取末尾的指针
|
|
getchar();
|
|
while (num--) {
|
|
while (!s.empty())s.pop();
|
|
getline(cin, p);
|
|
for (int i = 0; i < p.size(); i++) {
|
|
if (s.empty()) {
|
|
s.push(p[i]);
|
|
continue;
|
|
}
|
|
if (trans(p[i]) == s.top())s.pop();
|
|
else s.push(p[i]);
|
|
}
|
|
if (s.empty())printf("Yes\n");
|
|
else printf("No\n");
|
|
}
|
|
return 0;
|
|
} |