'commit'
This commit is contained in:
40
TangDou/LuoGuBook/Uva673.cpp
Normal file
40
TangDou/LuoGuBook/Uva673.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user