Littlecowr @ 2024-12-11 21:53:56
我的代码宝宝:
#include <bits/stdc++.h>
using namespace std;
stack<int>s;
string str;
int l;
int ci(char c){
switch(c){
case '(': return 1;
case ')': return 2;
case '[': return 3;
default: return 4;
}
}
char ic(int d){
switch(d){
case 1: return '(';
case 2: return ')';
case 3: return '[';
default: return ']';
}
}
int main(){
cin>>str;
l=str.size();
for(int i=0;i<l;i++){
if(ci(str[i])%2){
if(s.empty()) s.push(ci(str[i]));
else{
cout<<ic(s.top())<<ic(s.top()+1);
s.pop();
s.push(ci(str[i]));
}
}
else{
cout<<ic(s.top())<<ic(s.top()+1);
if(ic(s.top()+1)!=str[i]) cout<<ic(ci(str[i])-1)<<str[i];
s.pop();
}
}
cout<<'\n';
return 0;
}
救救孩子吧!在线等,挺急的!
by zzhengxi @ 2024-12-19 17:31:30
@Littlecowr switch case 要加break
by dendky @ 2024-12-21 10:16:24
@zzhengxi加了,没过,我试过了
by dendky @ 2024-12-21 10:16:47
@Littlecowr@zzhengxi我也很想知道为什么re
by zzhengxi @ 2024-12-21 12:43:45
@dendky 过不了,但保险啊
by zzhengxi @ 2024-12-21 12:44:44
@dendky 一起找啊
by zzhengxi @ 2024-12-21 12:51:18
测下这个:
([)]
答案为:
()[()]