美文网首页
给定前序和后序,计算中序有几种情况

给定前序和后序,计算中序有几种情况

作者: 来到了没有知识的荒原 | 来源:发表于2020-07-27 17:10 被阅读0次

    给定前序和后序,计算中序有几种情况

    a[i]==b[j]时,表示当前是root节点,如果a[i+1]==b[j-1],则表明子树既可以是左子树,也可以是右子数。

    #include <iostream>
    #include <cmath>
    const int M=100;
    using namespace std;
    
    int main(){
    //    freopen("data.txt","r",stdin);
        int count=0;
        string a,b;
        cin>>a>>b;
        for(int i=0;i<a.size();i++)
            for(int j=1;j<b.size();j++)
                if(a[i]==b[j]&&a[i+1]==b[j-1])
                    count++;
                
        cout<<pow(2,count)<<endl;
        return 0;
    }
    
    
    

    相关文章

      网友评论

          本文标题:给定前序和后序,计算中序有几种情况

          本文链接:https://www.haomeiwen.com/subject/mqttrktx.html