Dreaming_Zhong @ 2022-08-04 10:54:47
#include<bits/stdc++.h>
using namespace std;
stack<int> stk;
bool vis[105];
int main(){
memset(vis,0,sizeof(vis));
string s;
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='('||s[i]=='['||s[i]=='{'){
stk.push(i);
}else{
int xx=stk.top();
if(stk.empty()||s[i]!=s[xx]){
vis[i]=1;
}else{
stk.pop();
}
}
}
while(!stk.empty()){
int xx=stk.top();
vis[xx]=1;
stk.pop();
}
for(int i=0;i<s.size();i++){
if(!vis[i]) printf("%c",s[i]);
else{
if(s[i]=='('||s[i]==')') printf("()");
if(s[i]=='['||s[i]==']') printf("[]");
if(s[i]=='{'||s[i]=='}') printf("{}");
}
}
}
by shitouFL @ 2022-08-05 11:51:59
666
by Dreaming_Zhong @ 2022-08-07 22:50:41
@shitouFL 这是啥意思?是嘲讽吗?【震惊】
by Dreaming_Zhong @ 2022-08-07 22:52:42
@shitouFL 大神啊!看出来就给个具体点的回复呗!本蒟蒻太菜了!!!救救孩子吧!!!!
by shitouFL @ 2022-08-08 10:26:16
re救不了....
by shitouFL @ 2022-08-08 10:30:16
我改了yi点
#include<bits/stdc++.h>
using namespace std;
stack < int > stk;
stack < char > schar;
int vis[1005],len;
string s;
int main() {
cin>>s;
len=s.size();
for(int i=0; i<len; i++)
if(s[i]=='('||s[i]=='[')
stk.push(i),schar.push(s[i]);
else if(s[i]==')')
if(schar.top()!='(')
vis[i]=3;
else
schar.pop(),stk.pop();
else if(schar.top()!='[')
vis[i]=4;
else
schar.pop(),stk.pop();
while(!stk.empty())
{
if(schar.top()=='(')
vis[stk.top()]=1;
else
vis[stk.top()]=2;
schar.pop(),stk.pop();
}
for(int i=0; i<len; i++) {
if(vis[i]==0)printf("%c",s[i]);
if(vis[i]==1)printf("%c)",s[i]);
if(vis[i]==2)printf("%c]",s[i]);
if(vis[i]==3)printf("(%c",s[i]);
if(vis[i]==4)printf("[%c",s[i]);
}
printf("\n");
return 0;
}
但re....
by shitouFL @ 2022-08-08 10:31:23
I don't know why.