文章
79
粉丝
221
获赞
46
访问
196.6k
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
int n;
cin >> n;
string* s = new string[n];
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0,j, flag = 0; i < n; i++) {
stack <char> st;
for (j = 0; j < s[i].size(); j++) {
if (s[i][j] == '(' || s[i][j] == '[' || s[i][j] == '{' || s[i][j] == '<') {
if (st.empty()) {
st.push(s[i][j]);
continue;
}
if (s[i][j] == '{' && (st.top() == '[' || st.top() == '(' || st.top() == '<'))
break;
if (s[i][j] == '[' && (st.top() == '(' || st.top() == '<'))
break;
if (s[i][j] == '(' && (st.top() == '<'))
break;
st.push(s[i][j]);
}
else if (st.empty() || (s[i][j] == ')' && st.top() != '(') || (s[i][j] == ']' && st.top() != '[') || (s[i][j] == '}' && st.top() != '{') || (s[i][j] == '>' && st.top() !=...
登录后发布评论
暂无评论,来抢沙发