xiaobo19 @ 2024-07-23 14:51:37
#include<bits/stdc++.h>
using namespace std;
string s;int f=0,p[1000];
int main(){
cin >> s;
int len = s.size();
for(int i = 0;i < len;i++){
f=0;
if(s[i]=='('){
for(int j = 1;j <= len;j++){
if(s[i]=='('&&s[i+j]==')'&&p[i+j]==0){
p[i+j]=1,f=1;break;
}
}
if(f==1)cout << s[i];
else cout <<"()";
}
f=0;
if(s[i]==')'){
for(int j = 1;j <= len;j++){
if(s[i] == ')'&&s[i-j] == '('&&p[i-j]==0){
p[i-j]=1,f=1;break;
}
}
if(f==1)cout << s[i];
else cout <<"()";
}
f=0;
if(s[i]=='['){
for(int j = 1;j <= len;j++){
if(s[i]=='['&&s[i+j]==']'&&p[i+j]==0){
p[i+j]=1,f=1;break;
}
}
if(f==1)cout << s[i];
else cout <<"[]";
}
f=0;
if(s[i]==']'){
for(int j = 1;j <= len;j++){
if(s[i] == ']'&&s[i-j] == '['&&p[i-j]==0){
p[i-j]=1,f=1;break;
}
}
if(f==1)cout << s[i];
else cout <<"[]";
}
}
return 0;
}
by haimingbei @ 2024-07-23 14:53:43
题解是干啥用的?
by H2O2_ @ 2024-07-23 16:15:18
@haimingbei 老师不让查
?
by xiaobo19 @ 2024-07-23 17:01:14
@haimingbei teacher不让看呢,亲。