求助
查看原帖
求助
1235026
haimingbei楼主2024/8/3 13:15

只有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;
}
2024/8/3 13:15
加载中...