测( [ ) ] )有问题
#include <bits/stdc++.h>
using namespace std;
#define N 1005
int tot=0;
int book[N];
struct T{
int idx;
char c;
}a[N],stk[N];
int main(){
string s;
cin >> s;
for(int i=1;i<=s.size();i++){
a[i].c=s[i-1];
a[i].idx=i;
}
for(int i=1;i<=s.size();i++){
if(a[i].c=='('||a[i].c=='['){
tot++;
stk[tot].c=a[i].c;
stk[tot].idx=a[i].idx;
}
if(a[i].c==')'&&stk[tot].c=='('){
book[stk[tot].idx]=1;
book[a[i].idx]=1;
tot--;
continue;
}
if(a[i].c==']'&&stk[tot].c=='['){
book[stk[tot].idx]=1;
book[a[i].idx]=1;
tot--;
continue;
}
}
for(int i=1;i<=s.size();i++){
if(book[i]==1)cout << a[i].c;
else{
if(a[i].c=='(')
cout << a[i].c << ')';
if(a[i].c=='[')
cout << a[i].c << ']';
if(a[i].c==')')
cout << '(' << a[i].c;
if(a[i].c==']')
cout << '[' << a[i].c;
}
}
return 0;
}