40pts求助

P1241 括号序列

Aakkosetsumussa @ 2023-06-29 15:39:30

#include<bits/stdc++.h>
using namespace std;
typedef long long inr;
typedef unsigned long long unr;
#define fur(y) for(inr i=1;i<=y;i++)
#define fru(i,s,e) for(inr i=s;i<=e;i++)
#define frd(i,s,e) for(inr i=s;i>=e;i--)
#define el <<endl
#define sp <<" "<<
//stack<int>s;
string s1,s2;
int s[10000005];
int p=0;
int main() {
    ios::sync_with_stdio(false);
    cin>>s1;
    for(int i=0; i<s1.size(); i++)
        if(s1[i]=='[') {
            s[++p]=i;
            s2[i]=']';
        } else if(s1[i]=='(') {
            s[++p]=i;
            s2[i]=')';
        } else {
            if(p==0||s2[s[p]]!=s1[i]) {
                if(s1[i]==')') s2[i]='(';
                else s2[i]='[';
            } else {
                int t=s[p];
                p--;
                s2[t]=' ';
            }
        }

    for(int i=0; i<s1.size(); i++) {
        if(s2[i]=='('||s2[i]=='[') cout<<s2[i];
        cout<<s1[i];
        if(s2[i]==')'||s2[i]==']') cout<<s2[i];
    }
    return 0;
}

by Aakkosetsumussa @ 2023-06-29 15:41:22

剩下全是RE错误


|