P1827求调
  • 板块灌水区
  • 楼主S_Z_Xcoco
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/17 10:56
  • 上次更新2024/7/17 11:57:35
查看原帖
P1827求调
918508
S_Z_Xcoco楼主2024/7/17 10:56
#include<bits/stdc++.h>
using namespace std;
struct tree{
    int left,right;
}t[10010];
string qx,zx;
int build(int l1,int r1,int l2,int r2){
    int r=qx[l1];
    for(int i=l2;i<=r2;i++){
        if(zx[i]==qx[l1]){
            t[r].left=build(l1+1,l1+i-l2,l2,i-1);
            t[r].right=build(l1+i-l2+1,r1,i+1,r2);
        }
    }
    return r;
}
void post_order(int x){
    if(t[x].left)post_order(t[x].left);
    if(t[x].right)post_order(t[x].right);
    cout<<char(x);
}
int main(){
    cin>>zx>>qx;
    post_order(build(0,qx.size()-1,0,zx.size()-1));
    return 0;
}
2024/7/17 10:56
加载中...