P1827 [USACO3.4]美国血统 American Heritage【树的遍历】

题目

 

 代码

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
char in[100];
char pre[100];
int len=0;
void postorder(char in[],char pre[],int len)
{
    if (len <= 0)return;
    char root = pre[0];
    int i = 0;
    for ( i = 0; i < len; i++)
    {
        if (root == in[i])break;
    }
    postorder(in, pre + 1, i);
    postorder(in + i + 1, pre + i + 1, len - i - 1);
    printf("%c", root);


}

int main()
{
    string a, b;
    cin >> a >> b;
     len = a.length();
    for (int i = 0; i < a.length(); i++)
        in[i] = a[i];
    for (int i = 0; i < b.length(); i++)
        pre[i] = b[i];
    postorder(in, pre, len);
}

 

posted @ 2020-06-27 12:30  Jason66661010  阅读(147)  评论(0编辑  收藏  举报