提交时间:2023-08-23 19:04:37
运行 ID: 99775
#include <bits/stdc++.h> using namespace std; int n; char what(char a, char b)//判断字符串的类型 { if (a == 'F' || b == 'F')return 'F'; if ((a == 'I' && b == 'B') || (a == 'B' && b == 'I'))return 'F'; return a; } struct node { char val; node *left; node *right; }; void Order(node *a, int k) { if (k == 1) { cout << a->val; } if (k > 1) { Order(a->left, k - 1); Order(a->right, k - 1); cout << a->val; } } int Count = 0; void tree(node *a, int len, char *c) { if (len == 1) { a->val = c[Count]; Count++; } if (len > 1) { a->left = new node; tree(a->left, len - 1, c); a->right = new node; tree(a->right, len - 1, c); a->val = what(a->right->val, a->left->val); } } int main() { int len; cin >> n; len = (int) pow(2, n); char c[len + 1]; cin >> c; for (int i = 0; i < len + 1; ++i) { if (c[i] == '1')c[i] = 'I'; if (c[i] == '0')c[i] = 'B'; } node a; tree(&a, n + 1, c); Order(&a, n + 1); }