0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 06:38:48 +00:00

UVA673 平衡的括号 Parentheses Balance

R44264935
This commit is contained in:
Baoshuo Ren 2020-12-26 19:05:26 +08:00 committed by Baoshuo Ren
parent d02a6c25a2
commit 7f8bfbd3a1
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

34
problem/UVA673/UVA673.cpp Normal file
View 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;
}