8分!有AC,有WA,有RE!救救孩子吧!
查看原帖
8分!有AC,有WA,有RE!救救孩子吧!
1307445
Littlecowr楼主2024/12/11 21:53

我的代码宝宝:

#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;
}

救救孩子吧!在线等,挺急的!

2024/12/11 21:53
加载中...