简单题
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 27
char pre[maxn], in[maxn], post[maxn];
int len;
int find(int l, int r, char ch)
{
for (int i = l; i < r; i++)
if (in[i] == ch)
return i;
return -1;
}
void make(int prel, int prer, int inl, int inr)
{
if (prel >= prer)
return;
if (prel == prer - 1)
{
printf("%c", pre[prel]);
return;
}
int pos = find(inl, inr, pre[prel]);
make(prel + 1, prel + pos - inl + 1, inl, pos);
make(prel + pos - inl + 1, prer, pos + 1, inr);
printf("%c", pre[prel]);
}
int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%s%s", pre, in) != EOF)
{
len = strlen(pre);
make(0, len, 0, len);
printf("\n");
}
return 0;
}