文件目录

#include <bits/stdc++.h>
using namespace std;
struct node
{
    char c;
    int line = 0;
    node *l = nullptr, *r = nullptr;
    node(char a, int b)
    {
        c = a;
        line = b;
    }
};
string xx, zx;
node *getxx(string xx, string zx)
{
    if (xx.size() == 0)
        return nullptr;
    if (xx.size() == 1)
        return new node(xx[0], 1);
    char root = xx[0];
    int line = 0;
    int id = zx.find(root);
    node *left = getxx(xx.substr(1, id), zx.substr(0, id));
    node *right = getxx(xx.substr(id + 1), zx.substr(id + 1));
    if (left != nullptr)
        line += left->line;
    if (right != nullptr)
        line += right->line;
    node *rt = new node(root, line);
    rt->l = left;
    rt->r = right;
    return rt;
}
void xxbl(node *p)
{
    if (p == nullptr)
        return;
    string s(p->line, p->c);
    cout << s << endl;
    xxbl(p->l);
    xxbl(p->r);
}
int main()
{
    cin >> xx >> zx;
    node *root = getxx(xx, zx);
    xxbl(root);
    return 0;
}