bjqxszx_zhongqide @ 2024-04-13 12:07:14
#include<bits/stdc++.h>
using namespace std;
stack<int>z;
string a,b;
int main(){
cin>>a;
int n=a.size();
for(int i=0;i<n;i++){
if(a[i]=='('){
z.push(i);
b[i]=')';
}
if(a[i]=='['){
z.push(i);
b[i]=']';
}
if(a[i]==')'||a[i]==']'){
if(z.empty()||b[z.top()]!=a[i]){
if(a[i]==')'){
b[i]='(';
}else{
b[i]='[';
}
}else{
b[z.top()]=' ';
}
}
}
for (int i=0;i<n;i++){
if(b[i]=='('||b[i]=='['){
cout<<b[i];
}
cout<<a[i];
if(b[i]==')'||b[i]==']'){
cout<<b[i];
}
}
cout<<endl;
}
by a987654 @ 2024-06-22 13:27:37
把
z.empty
改成
z.size()!=0