mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 21:16:27 +00:00
UVA673 平衡的括号 Parentheses Balance
R44264935
This commit is contained in:
parent
d02a6c25a2
commit
7f8bfbd3a1
34
problem/UVA673/UVA673.cpp
Normal file
34
problem/UVA673/UVA673.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int t;
|
||||
cin >> t;
|
||||
getchar();
|
||||
while (t--) {
|
||||
string s;
|
||||
stack<char> st;
|
||||
getline(cin, s);
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
if (s[i] == '(' || s[i] == '[') {
|
||||
st.push(s[i]);
|
||||
}
|
||||
else if (st.empty() || s[i] == ')' && st.top() != '(' || s[i] == ']' && st.top() != '[') {
|
||||
cout << "No" << endl;
|
||||
goto end;
|
||||
}
|
||||
else {
|
||||
st.pop();
|
||||
}
|
||||
}
|
||||
if (st.empty()) {
|
||||
cout << "Yes" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "No" << endl;
|
||||
}
|
||||
end:;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user