求助,30分
查看原帖
求助,30分
372729
创造君楼主2021/8/27 22:04
#include <bits/stdc++.h>
using namespace std;
#define MAXN 4096

int n;
char tree[MAXN+5];

void build_tree(string str, int x) {
    if (str.size() == 1) {
        if (str == "0") {
            tree[x] = 'B';
        } else if (str == "1") {
            tree[x] = 'I';
        }
        return;
    }
    tree[x] = 'F';
    build_tree(str.substr(0, str.size()/2), 2*x);
    build_tree(str.substr(str.size()/2), 2*x+1);
}

void print_tree(int x) {
    if (tree[x] == 0) {
        return;
    }
    print_tree(2*x);
    print_tree(2*x+1);
    cout << tree[x];
}

int main() {
    string str;
    cin >> n >> str;
    build_tree(str, 1);
    print_tree(1);
    return 0;
}
2021/8/27 22:04
加载中...