Suboil @ 2023-08-02 21:51:53
#include <bits/stdc++.h>
using namespace std;
string mb[6] = {"()","[]","(())","([])","()[]","()[()]"};
queue<string> q;
int main(){
string s,t;
cin >> s;
int idx = 0,flag = 0;
while(1) {
if(idx >= s.size()) break;
flag = 0;
for(int i = 5;i >= 0;i--) {
if(idx + mb[i].size() > s.size()) continue;
t = s.substr(idx,mb[i].size());
if(mb[i] == t) {
q.push(t);
flag = 1;
idx += mb[i].size();
break;
}
}
if(!flag) {
if(s[idx] == '(' || s[idx] == ')') {
q.push("()");
}else if(s[idx] == '[' || s[idx] == ']') {
q.push("[]");
}
idx++;
}
}
while(!q.empty()) {
cout << q.front();
q.pop();
}
cout << endl;
return 0;
}
by 123aaa45 @ 2023-08-04 12:58:55
你把空间最开始就定200,resize一下