1 / 207
文档名称:

ACM测试题及其答案.doc

格式:doc   页数:207
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

ACM测试题及其答案.doc

上传人:164922429 2014/1/19 文件大小:0 KB

下载得到文件列表

ACM测试题及其答案.doc

文档介绍

文档介绍:ACM试题及参考答案
.
1045:
Description
Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.
This is an example of one of her creations:
        D
       / \
      /   \
     B     E
    / \     \  
   /   \     \
  A    C      G
             /
            /
           F
To record her trees for future generations, she wrote down two strings for each tree: a preorder traversal (root, left subtree, right subtree) and an inorder traversal (left subtree, root, right subtree). For the tree drawn above the preorder traversal is DBACEGF and the inorder traversal is ABCDEFG.
She thought that such a pair of strings would give enough information to reconstruct the tree later (but she never tried it).
Now, years later, looking again at the strings, she realized that reconstructing the trees was indeed possible, but only because she never had used the same letter twice in the same tree.
However, doing the reconstruction by hand, soon turned out to be tedious.
So now she asks you to write a program that does the job for her!
Input
The input will contain one or more test cases.
Each test case consists of one line containing two strings preord and inord, representing the preorder traversal and inorder traversal of a binary tree. Both strings consist of unique capital letters. (Thus they are not longer than 26 characters.)
Input is terminated by end of file.
Output
For each test case, recover Valentine's binary tree and print one line containing the tree's postorder traversal (left subtree, right subtree, root).
Sample Input
DBACEGF ABCDEFG
BCAD CBAD
Sample Output
ACBFGED
CDAB
#include<>
#include<>
char pre[30],in[30];
void recover(int pi,int pj,int ii,int ij)
{
    if(pi+1>pj)
        return;
    int i=ii;
    while(in[i]!=pre[pi])
        i++;
    for(int j=pi; j<pj-1; j++)
        pre[j]=pre[j+1];
    pre[pj-1]=in[i];
 

最近更新

2026年网络安全知识竞赛题库及答案(基础+提升.. 40页

2026年网络安全知识竞赛题库附答案(达标题).. 39页

2026年网络安全知识竞赛题库【综合卷】 39页

小学历史与文化知识竞赛题库100道含答案(考试.. 37页

2026年网络安全知识竞赛题库含完整答案(夺冠.. 39页

新安全生产法知识竞赛试题库含答案(培优) 44页

小学历史与文化知识竞赛题库100道【培优】 37页

小学历史与文化知识竞赛题库100道及参考答案(.. 37页

小学历史与文化知识竞赛题库100道附完整答案【.. 37页

最新煤气操作证考试题100道及1套参考答案 39页

新安全生产法知识竞赛试题库含答案【新】 43页

新安全生产法知识竞赛试题库附参考答案【模拟.. 43页

最新煤气操作证考试题100道及完整答案(夺冠系.. 38页

最新煤气操作证考试题100道含答案【夺分金卷】.. 39页

最新全国政法队伍教育整顿知识竞赛试题库含完.. 39页

最新煤气操作证考试题100道附答案【考试直接用.. 38页

最新全国政法队伍教育整顿知识竞赛试题库附答.. 40页

最新煤气操作证考试题100道及完整答案【夺冠】.. 39页

最新煤气操作证考试题100道带答案(综合卷) 39页

人工智能生成内容权益保护的实践检视及优化 8页

2025年助听器合作协议书 69页

2025年医用真空负压机项目发展计划 60页

2025年医学检验项目合作计划书 80页

2025年全包覆型镀铝玻璃纤维合作协议书 70页

2025年农林牧渔专用仪器仪表项目发展计划 87页

2026年安徽城市管理职业学院单招职业适应性考.. 37页

2025年湖南省建设工程工程量清单计价办法(新).. 51页

2025年江西信息应用职业技术学院单招职业适应.. 127页

2025年江西信息应用职业技术学院单招职业倾向.. 73页

喝酒给老婆的检讨书 6页