Code:
#include <bits/stdc++.h>
using namespace std;
void read(int &x){
int s=0,w=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-'){
w=-1;
}
c=getchar();
}
while(c>='0'&&c<='9'){
s=s*10+c-'0';
c=getchar();
}
x=s*w;
return;
}
int n;
char s[100000];
char tree[100000];
void dfs(int x){
if(x>=(1<<n)){
if(s[x]==1){
tree[x]='I';
}
else{
tree[x]='B';
}
printf("%c",tree[x]);
return;
}
dfs(x*2);
dfs(x*2+1);
if(tree[x*2]==tree[x*2+1]){
tree[x]=tree[x*2];
}
else{
tree[x]='F';
}
printf("%c",tree[x]);
return;
}
int main(){
read(n);
for(int i=pow(2,n);i<=pow(2,n+1)-1;i++){
s[i]=getchar();
}
// scanf("%s",s+1);
dfs(1);
return 0;
}
Please help me and I can follow you