没有输出!!!求助!!!
查看原帖
没有输出!!!求助!!!
521302
landernal楼主2022/2/24 20:49
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int n, a[1026];
int len;
struct node{
    string name;
    node *left, *right;
};
node *create(int lenn, int bear){
    node *root = new node;
    if(lenn == 0) {
        root = NULL;
        return root;
    }
    int x = 0;
    if(bear) {
        for(int i = 1; i <= lenn; i++) {
            x += a[i];
        }
    }else{
        for(int i = lenn; i <= len; i++) {
            x += a[i];
        }
    }
    if(!x) {
        root -> name = "B";
    }else if(x == lenn) {
        root -> name = "I";
    }else{
        root -> name = "F";
    }
    int lennn = lenn / 2;
    root -> left = create(lennn, 1);
    root -> right = create(lennn, 2);
    return root;
}
void postordertree(node *root) {
    if(root == NULL) {
        return;
    }else{
        postordertree(root -> left);
        postordertree(root -> right);
        cout << root -> name << " ";
    }
}

int main(){
    cin >> n;
    len = pow(2, n);
    int g = 0;
    for(int i = 1; i <= pow(2, n); i++) {
        cin >> a[i];
        g += a[i];
    }
    node *root1 = create(len / 2, 1);
    node *root2 = create(len / 2, 2);
    postordertree(root1);
    postordertree(root2);
    if(!g) {
        cout << "B" << endl;
    }else if(g == len) {
        cout << "I" << endl;
    }else{
        cout << "F" << endl;
    }
    return 0;
}

2022/2/24 20:49
加载中...