63分求dalao指教

P1241 括号序列

C琉璃 @ 2021-06-02 18:29:55

#include<iostream>
#include<cstdio>
using namespace std;
int l=0,m=0;
bool bb[1000000];
int main() 
{
    int i=1;
    char a[100000];
    char b[100000];
    while(cin>>a[i])
    {
        if(a[i]=='(')
        b[i]=')';
        if(a[i]=='[')
        b[i]=']';
        if(a[i]==')')
        {
            b[i]='(';
            for(int j=i-1;j>=1;j--)
            {
                if(b[j]==')'&&bb[j]==0)
                {
                    bb[i]=1;
                    bb[j]=1;
                    break;
                }
            }
        }
        if(a[i]==']')
        {   
            b[i]='[';
            for(int j=i-1;j>=1;j--)
            {
                if(b[j]==']'&&bb[j]==0)
                {
                    bb[i]=1;
                    bb[j]=1;
                    break;
                }
            }
        }
        //cout<<a[i]<<" "<<b[i];
        i++;
    }
    for(int j=1;j<i;j++)
    {
        //cout<<bb[j];
        if(bb[j]==0&&(a[j]=='('||a[j]=='['))
        cout<<a[j]<<b[j];
        if(bb[j]==0&&(a[j]==')'||a[j]==']'))
        cout<<b[j]<<a[j];
        if(bb[j]==1)
        cout<<a[j];
    }
}

by C琉璃 @ 2021-06-02 18:31:18

1,2,3,12,13WA,不想努力了等待大佬帮忙


by Mr_ZBKF @ 2021-06-25 16:52:13

qp


by 风羽跃 @ 2021-06-30 19:27:37

@C琉璃 忽略了题目条件


by 风羽跃 @ 2021-06-30 19:28:40

补全的括号必须匹配,[(])这样的就不匹配


by 风羽跃 @ 2021-06-30 19:29:29

我一上来也是这么错的555


by C琉璃 @ 2021-07-21 09:33:07

@风羽跃 谢谢dalao


|