zhouyk0501 @ 2023-10-19 08:53:51
帮忙hack一下如下代码
#include<bits/stdc++.h>
using namespace std;
int stk[110],op;
int main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++){
if(op==0){
stk[++op]=i;
}else{
if(s[i]=='('){
stk[++op]=i;
}if(s[i]=='['){
stk[++op]=i;
}if(s[i]==')'){
// cout<<s[stk[op]]<<" ";
if(s[stk[op]]=='(') op--;
else stk[++op]=i;
// cout<<s[stk[op]]<<" ";
}if(s[i]==']'){
// cout<<s[stk[op]]<<" ";
if(s[stk[op]]=='[') op--;
else stk[++op]=i;
// cout<<s[stk[op]]<<" ";
}
}
}int xp=1;
// for(int i=1;i<=op;i++) cout<<stk[i]<<" ";
for(int i=0;i<s.size();i++){
if(stk[xp]==i&&op>=xp){
if(s[i]=='('||s[i]==')') cout<<"()";
if(s[i]=='['||s[i]==']') cout<<"[]";
xp++;
}else{
cout<<s[i];
}
}
}
by Ace_FutureOIer @ 2023-10-19 09:48:12
@zhouyukun0501 建议拿题解代码对拍
by zhouyk0501 @ 2023-10-19 09:59:08
@chenyining6xh 谢谢,刚刚在题解中获得了一组hack数据