求救,才12分

P1241 括号序列

``` #include <bits/stdc++.h> using namespace std; int top,w[110]; string a; char s[110],c[110]; int main() { cin >> a; int n=a.length(); for(int i=0;i<n;i++) { if(a[i] == '(' || a[i] == '[') { s[++top]=a[i]; w[top]=i; if(a[i] == '(') c[i]=')'; else c[i]=']'; } if(a[i] == ')') { if(top && s[top] == '(') {c[w[top]]=' '; top--;} else c[i]='('; } if(a[i] == ']') { if(top && s[top] == '[') {c[w[top]]=' '; top--;} else c[i]='['; } } for(int i=0;i<n;i++) { if(c[i] == '(' || c[i] == '[') printf("%c%c",c[i],a[i]); else if(c[i] == ')' || c[i] == ']') printf("%c%c",a[i],c[i]); else printf("%c",a[i]); } return 0; } ``` @[Jared0503](/user/1074812)
by D23lhc @ 2024-01-23 20:13:02


给个关注 QWQ
by D23lhc @ 2024-01-23 20:14:01


@[D23lhc](/user/1065153) 已关,谢谢
by Jared0503 @ 2024-01-24 09:01:16


|