标签:jdee rfs avd mpeg osx ssrs w3m get caff
#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]==1)return; vis[i]=1; pr(map[i]-1,i+1),i=map[i];continue; } if(ch[i]==‘)‘){ if(vis[i]==1)return; vis[i]=1; pr(mp[i]+1,i-1),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]==1)return; vis[i]=1; pr(map[i]-1,i+1),i=map[i];continue; } if(ch[i]==‘)‘){ if(vis[i]==1)return; vis[i]=1; pr(mp[i]+1,i-1),i=mp[i];continue; } } } } int main(){ //freopen("Cola.txt","r",stdin); scanf("%s",ch+1); len=strlen(ch+1); for(int i=1;i<=len;i++){ if(ch[i]==‘(‘)st[++top]=i; if(ch[i]==‘)‘)map[st[top]]=i,mp[i]=st[top],top--; } pr(1,len); }
标签:jdee rfs avd mpeg osx ssrs w3m get caff
原文地址:http://www.cnblogs.com/thmyl/p/7576888.html