文章
20
粉丝
412
获赞
13
访问
165.3k
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while(n--) {
string s;
cin >> s;
int len = s.length();
stack<char> st;
for(int i = 0;i < len;i++) {
if(!st.empty()) {
if(s[i] == '(' || s[i] == '[' || s[i] == '{')
st.push(s[i]);
else if(st.top() == '(' && s[i] == ')' || st.top() == '[' && s[i] == ']' || st.top() == '{' && s[i] == '}')
st.pop();
else continue;
}
else if(s[i] == '(' || s[i] == '[' || s[i] == '{' || s[i] == ')' || s[i] == ']' || s[i] == '}')
st.push(s[i]);
else continue;
}
if(!st.empty()) cout << "no" << endl;
else cout << "yes" << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发