#include <bits/stdc++.h>
using namespace std;
stack<int>s;
int main() {
string str;
cin >> str;
int maxlen = 0, start = 0;
s.push(-1);
for (int i = 0; i < str.size(); i++) {
if (str[i] == '(' || str[i] == '[')
s.push(i);
else {
if (s.size() == 1) {
s.pop();
s.push(i);
} else {
char top = str[s.top()];
s.pop();
if (str[i] == ')' && top == '(' || str[i] == ']' && top == '[') {
int len = i - s.top();
if (maxlen < len) {
maxlen = len;
start = s.top() + 1;
}
} else {
s.pop();
s.push(i);
}
}
}
}
cout << str.substr(start, maxlen);
return 0;
}
全部回复 共 0 条
还没有人回复。往下写第一条。
发表回复
登录后即可回复本帖,与出题人和同学一起讨论。
登录