通过了三个测试点,其他超时了
by lpl2002 @ 2023-05-04 19:40:39
```c
#include <stdio.h>
#include <stdlib.h>
void creatTree(char *a, char *b, int af, int ae, int bf, int be)
{
int root;
for (root = 0; root <= ae; root++)
if (a[root] == b[bf])
break;
if (root - af != 0)
creatTree( a, b, af, root - 1, bf + 1, bf + root - af);
if (root - ae != 0)
creatTree( a, b, root + 1, ae, bf + root - af + 1, be);
printf("%c", b[bf]);
}
int main()
{
char a[26]; // 中序
char b[26]; // 前序
int i = 0;
int j = 0;
char ch;
while ((ch = getchar()) != '\n')
{
if (ch > 'Z' || ch < 'A')
continue;
a[i] = ch;
i++;
}
while ((ch = getchar()) != '\n')
{
if (ch > 'Z' || ch < 'A')
continue;
b[j] = ch;
j++;
}
creatTree(a, b, 0, i - 1, 0, j - 1);
}
```
修改之后仍然超时
by lpl2002 @ 2023-05-04 20:11:49