只有24分,AC 3个点,WA 3个点,RE 6个点 求指出哪有问题(勿发代码,指错)
/*
2、P1241 括号序列
*/
#include<bits/stdc++.h>
using namespace std;
stack <char> st;
char trans(char c){
if(c==')')return '(';
else if(c==']')return '[';
}
int main(){
string s;
cin>>s;
if(s.size()==0){
return 0;
}
for(int i=0;i<s.size();i++){
if(s[i]=='(' || s[i]=='[')st.push(s[i]);
else {
if(trans(s[i])==st.top()){
cout<<st.top()<<s[i];
st.pop();
}
else st.push(s[i]);
}
}
while(!st.empty()){
if(st.top()=='(' || st.top()==')') cout<<'('<<')';
else if(st.top()=='[' || st.top()==']') cout<<'['<<']';
st.pop();
}
return 0;
}