1. 程式人生 > >【UVA】536 Tree Recovery(樹型結構基礎)

【UVA】536 Tree Recovery(樹型結構基礎)

cnblogs using include http tree c++ code div str

題目

題目
?


?

分析

莫名A了
?


?

代碼

#include <bits/stdc++.h>
using namespace std;
string s1,s2;
void build(int l1,int r1,int l2,int r2)
{
    int root=l1,p=l2;
    if(l1>r1) return;
    while(s2[p]!=s1[root] && p<=r2) p++;
    int cnt=p-l2;
    build(l1+1,l1+cnt,l2,p-1);
    build(l1+cnt+1
,r1,p+1,r2); printf("%c",s1[root]); } int main() { while(cin>>s1>>s2) { build(0,s1.length()-1,0,s2.length()-1); puts(""); } return 0; }

【UVA】536 Tree Recovery(樹型結構基礎)