UVa673
程序员文章站
2024-03-19 09:29:52
...
#include <stack>
#include <string>
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
getchar();
while(T--) {
string s;
getline(cin, s);
stack<char> st;
bool flag = true;
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() == '(')
st.pop();
else if(!st.empty() && s[i] == ']' && st.top() == '[')
st.pop();
else
flag = false;
}
if(flag && st.empty())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}