laobocai @ 2023-08-23 15:09:42
44分蒟蒻求助,怎么改啊!!!
#include<bits/stdc++.h>
using namespace std;
struct id{
int s;
char c;
}a;
int main(){
deque<id> q;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
a.c=s[i];
a.s=i;
if(!q.empty()){
if((q.back().c=='(' && s[i]==')')||(q.back().c=='[' && s[i]==']'))
q.pop_back();
else
q.push_back(a);
}
else
q.push_back(a);
}
for(int i=0;i<s.length();i++){
if(!q.empty()){
if(q.front().s==i){
if(s[i]=='[')
cout<<"[]";
else
cout<<"()";
q.pop_front();
}
else
cout<<s[i];
}
else
cout<<s[i];
}
return 0;
}