52分,求助大佬
查看原帖
52分,求助大佬
983305
hyx0826楼主2023/8/23 11:34

测评结果

#include<bits/stdc++.h>
using namespace std;
int main(){
	int bj[1000]={0};
	string s;
	int t;
	stack<char> a;
	stack<int> a1;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='('||s[i]=='['){
			a.push(s[i]);
			a1.push(i);
			bj[i]=1;
		}
		else{
			if(s[i]==')'&&a.top()=='('){
				a.pop();
				bj[a1.top()]=0;
				a1.pop();
			}
			else {
				if(s[i]==']'&&a.top()=='['){
					a.pop();
					bj[a1.top()]=0;
					a1.pop();
				}
				else{
					bj[i]=1;
				}
			}
		}
	}
	for(int i=0;i<s.size();i++){
		if(bj[i]==0) cout<<s[i];
		else {
			if(s[i]=='('||s[i]==')') cout<<"()";
			else cout<<"[]";
		}
	}
	return 0;
}
2023/8/23 11:34
加载中...