大佬佬们,70求助

P1241 括号序列

初嫁QAQ @ 2020-04-25 09:52:00

要是可以的话举个反例可以吗QAQ

# include <iostream>
# include <cstdio>
# include <stack>
using namespace std;
stack<char> a;
stack<int> b;
string s,s2;
char c[10010];
bool vis[2][10010],vis2[2][10010];
int main(){
    cin>>s;
    for(int i=s.length()-1;i>=0;i--){
        bool flag=0;
        c[i+1]=s[i];
        if(c[i+1]=='('){
            if(a.size()>0&&a.top()==')')
                a.pop(),b.pop();
            else
                vis[0][i+1]=1,a.push(c[i+1]);
        }
        if(c[i+1]=='['){
            if(a.size()>0&&a.top()==']')
                a.pop(),b.pop();
            else
                vis[1][i+1]=1,a.push(c[i+1]);
        }
        if(c[i+1]==']'||c[i+1]==')'){
            a.push(c[i+1]);
            b.push(i+1);
        }
    }
    while(b.size()>0){
        int e=b.top();
        b.pop();
        if(c[e]==']')
            vis2[1][e-1]=1;
        else
            vis2[0][e-1]=1;
    }
    if(vis2[1][0])
        cout<<'[';
    if(vis2[0][0])
        cout<<'(';
    for(int i=1;i<=s.length();i++){
        cout<<c[i];
        if(vis[0][i])   
            cout<<')';
        if(vis[1][i])   
            cout<<']';
        if(vis2[0][i])  
            cout<<'(';
        if(vis2[1][i])  
            cout<<'[';
    }
    return 0;
}

by 初嫁QAQ @ 2020-04-27 11:58:28


by 莫负韶华 @ 2020-05-05 10:01:29

我也70...( _ _)ノ|


|