就这道题,10001011变成1 0 0 0 1 0 1 1,怎么存啊,就差一点
#include <iostream>
#include <cmath>
using namespace std;
int x, n, a[1026], len;
char tr[1026];
void fbi(int begin, int end, int j){
if(j > pow(2, (n + 1)) - 1) {
return;
}
int sum = 0;
for(int i = begin; i <= end; i++) {
sum = sum + a[i];
}
if(sum == 0) {
tr[j] = 'B';
}else if(sum == end - begin + 1) {
tr[j] = 'I';
}else{
tr[j] = 'F';
}
fbi(begin, end - (end - begin + 1) / 2, j * 2);
fbi((end - begin + 1) / 2 + begin, end, j * 2 + 1);
}
void putorder(int j) {
if(j > pow(2, (n + 1)) - 1) {
return;
}else{
putorder(j * 2);
putorder(j * 2 + 1);
cout << tr[j];
}
}
int main(){
cin >> n;
len = pow(2, n);
for(int i = 1; i <= len; i++) {
cin >> a[i];
}
if(n == 0) {
if(a[1] == 1) {
cout << "I" << endl;
}else{
cout << "B" << endl;
}
return 0;
}
fbi(1, len, 1);
putorder(1);
return 0;
}