52分,求助大佬

P1241 括号序列

hyx0826 @ 2023-08-23 11:34:43

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

by 2013wu @ 2023-08-23 11:50:16

我会!!!

-

-

-

-

-

-

-

-

-

-

-

-

-

个屁


|