HeCao2008 @ 2022-05-26 22:59:40
#include<bits/stdc++.h>
using namespace std;
char zuo[101],you[101];
int top,sta[101];
int main(){
string s;
cin>>s;
int len=s.length();
for(int i=0;i<len;i++){
if(s[i]=='('||s[i]=='['){
zuo[++top]=s[i];
sta[top]=i;
if(s[i]=='(')you[i]=')';
else you[i]=']';
}
if(s[i]==')'){
if(top!=0&&zuo[top]=='('){
you[sta[top]]=' ';
top--;
}
else you[i]='(';
}
if(s[i]==']'){
if(top!=0&&zuo[top]=='['){
you[sta[top]]==' ';
top--;
}
else you[i]='[';
}
}
for(int i=0;i<len;i++){
if(you[i]=='('||you[i]=='[')cout<<you[i]<<s[i];
else if((you[i]==')'||you[i]==']'))cout<<s[i]<<you[i];
else cout<<s[i];
}
return 0;
}
哪里错了感觉思路挺对的