• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Tree Recovery

            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

            告訴你樹(shù)的先序遍歷,中序遍歷,求其后序遍歷
            #include<cstdio>
            #include
            <cstring>
            #include
            <iostream>
            using namespace std;
            char ch1[30],ch2[30],ch[30];
            int len;
            void dfs(int s1,int e1,int s2,int e2){
                
            if(s1>e1) return;
                ch[
            --len]=ch1[s1];
                
            int i;
                
            for(i=s2;ch2[i]!=ch1[s1] && i<=e2;i++);
                dfs(s1
            +i-s2+1,e1,i+1,e2);
                dfs(s1
            +1,s1+i-s2,s2,i-1);
            }
            int main(){
                
            while(~scanf("%s%s",ch1,ch2)){
                    len
            =strlen(ch1);
                    ch[len]
            ='\0';
                    dfs(
            0,len-1,0,len-1);
                    printf(
            "%s\n",ch);
                }
            }

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            posts - 3, comments - 1, trackbacks - 0, articles - 16

            Copyright © lenohoo

            久久这里只有精品18| 污污内射久久一区二区欧美日韩| 国内精品久久久久影院网站| 久久久久亚洲AV片无码下载蜜桃| 久久精品国产日本波多野结衣| 欧美国产精品久久高清| 青青青青久久精品国产h久久精品五福影院1421| 2021精品国产综合久久| 久久久综合九色合综国产| 久久久久亚洲精品天堂久久久久久 | 精品999久久久久久中文字幕| 欧美久久精品一级c片片| 久久亚洲中文字幕精品一区| 久久久久久综合一区中文字幕| 欧美成a人片免费看久久| 国产精品久久波多野结衣| 性做久久久久久免费观看| 久久er国产精品免费观看2| 97久久国产露脸精品国产| 久久国产成人| 国产精品午夜久久| 蜜桃麻豆www久久| 少妇久久久久久久久久| 久久人人爽人人爽人人片AV麻烦| 国产高清美女一级a毛片久久w | 国产精品美女久久久免费 | 久久香蕉国产线看观看99| AV无码久久久久不卡蜜桃| 亚洲国产精品综合久久网络| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产亚洲美女精品久久久久狼| 精品无码久久久久国产动漫3d | 色欲av伊人久久大香线蕉影院| 日本精品久久久久影院日本| 国产亚洲精午夜久久久久久 | 久久久久亚洲AV片无码下载蜜桃 | 国产成人久久激情91| 99久久精品毛片免费播放| 国产美女久久久| 青青草原1769久久免费播放| 亚洲成人精品久久|