1 solutions

  • 0
    @ 2024-3-30 20:36:30

    贴个代码吧

    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <string>
    #include <list>
    #include <map>
    #include <set>
    #include <queue>
    #include <vector>
    #include <stack>
    using namespace std;
    string preOrder,inOrder;
    void postOrder(int prel,int prer,int inl,int inr)
    {
        if(prel>prer)
            return ;
        char root;
        root=preOrder[prel];
        int ind=inl;
        for(int i=inl;i<=inr;i++)
        {
            if(inOrder[i]==root)
            {
                ind=i;
                break;
            }
           
        }
        postOrder(prel+1,ind-inl+prel,inl,ind-1);
        postOrder(ind-inl+prel+1,prer,ind+1,inr);
        cout<<root;
    }
    int main(){
        cin>>preOrder>>inOrder;
        postOrder(0,preOrder.length()-1,0,inOrder.length()-1);
        
        
        
        return 0;
    }
    

    Information

    ID
    6854
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    2
    Accepted
    2
    Uploaded By