自己测试找不出问题,样例也过了,但就是不满
#include<bits/stdc++.h>
using namespace std;
string a;
char b[520],c[520];
int len,top;
int main(){
cin>>a;
b[0]=a[0];
len=a.length();
for(int i=1;i<len;i++){
if(top<0){
b[i]=a[i];
top=i;
continue;
}
if((b[top]=='('&&a[i]==')')||(b[top]=='['&&a[i]==']')){
c[top]=b[top];
c[i]=a[i];
b[top]=b[i]='0';
while(b[top]=='0') top--;
}
else{
b[i]=a[i];
top=i;
}
}
for(int i=0;i<len;i++){
if(b[i]=='0') cout<<c[i];
if(b[i]=='('||b[i]==')') cout<<"()";
if(b[i]=='['||b[i]==']') cout<<"[]";
}
return 0;
}