UVa 536 Tree Recovery——树的遍历

网友投稿 529 2022-11-07

UVa 536 Tree Recovery——树的遍历

UVa 536 Tree Recovery——树的遍历

#include #include #include #include #include using namespace std;string a, b;void dfs(int p1, int p2, int q1, int q2, int root) { if (p1 > p2) return; for (root = q1; a[p1] != b[root]; root++); dfs(p1 + 1, p1 + root - q1, q1, root - 1, 0); dfs(p1 + root - q1 + 1, p2, root + 1, q2, 0); cout << b[root];}int main(){ while (cin >> a >> b) { int n = a.size() - 1; dfs(0, n, 0, n, 0); cout << endl; } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:POJ 1321 棋盘问题——dfs
下一篇:UVa 439 Knight Moves——bfs
相关文章

 发表评论

暂时没有评论,来抢沙发吧~