双链表搞完了
#include<bits/stdc++.h> using namespace std; #define maxn 1000005 int tot,bac[maxn],fa[maxn]; char a[maxn],b[maxn]; int main(){ cin>>(a+1); cin>>(b+1); tot=0; //cout<<strlen(a)<<endl; int la=strlen(a+1),lb=strlen(b+1); for(int j=0;j<=la;j++){ fa[j]=tot-1; if(j==strlen(a+1)) bac[j]=-1; else bac[j]=++tot; //cout<<j<<" "<<fa[j]<<" "<<bac[j]<<endl; } bool i=0; int z=1; for(int j=1;j<=lb;j++){ if(i>0){ if(b[j]=='e'){ i=0; continue; } int l=fa[z]; a[++tot]=b[j]; fa[tot]=l; bac[tot]=z; fa[z]=tot; bac[l]=tot; z=bac[tot]; }else{ if(b[j]=='i'){ i=1; continue; } else if(b[j]=='x'){ int l=fa[z]; int r=bac[z]; //cout<<l<<" "<<r<<endl; if(r!=-1){ fa[r]=l; bac[l]=r; z=bac[l]; }else{ z=l; bac[l]=-1; } } else if(b[j]=='f'){ char c=b[j+1]; for(int ii=bac[z];ii!=-1;ii=bac[ii]){ if(a[ii]==c){ z=ii; break; } } j++; } else if(b[j]=='l'){ if(bac[z]!=-1) z=bac[z]; } else if(b[j]=='h'){ z=fa[z]; if(z==0) z=bac[z]; } } } int q=0; while(q!=-1){ q=bac[q]; cout<<a[q]; } }