描述

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 500010
int len,map[maxn],st[maxn],top,mp[maxn];
char ch[maxn],vis[maxn];
void pr(int l,int r){
if(l<=r){
for(int i=l;i<=r;i++){
if(ch[i]!='('&&ch[i]!=')'){
printf("%c",ch[i]);continue;
}
if(ch[i]=='('){
if(vis[i]==)return;
vis[i]=;
pr(map[i]-,i+),i=map[i];continue;
}
if(ch[i]==')'){
if(vis[i]==)return;
vis[i]=;
pr(mp[i]+,i-),i=mp[i];continue;
}
}
}
else {
for(int i=l;i>=r;i--){
if(ch[i]!='('&&ch[i]!=')'){
printf("%c",ch[i]);continue;
}
if(ch[i]=='('){
if(vis[i]==)return;
vis[i]=;
pr(map[i]-,i+),i=map[i];continue;
}
if(ch[i]==')'){
if(vis[i]==)return;
vis[i]=;
pr(mp[i]+,i-),i=mp[i];continue;
}
}
}
}
int main(){
//freopen("Cola.txt","r",stdin);
scanf("%s",ch+);
len=strlen(ch+);
for(int i=;i<=len;i++){
if(ch[i]=='(')st[++top]=i;
if(ch[i]==')')map[st[top]]=i,mp[i]=st[top],top--;
}
pr(,len);
}
05-25 23:26