Thinking Process

what a easy excersize! but i waste much time on input. DAMN IT!
Overall, judge the length of S first. if length == 1, output it directly. otherwise, construct the tree and finally judge the type of S and output type!

Code

#include<stdio.h>
#include<math.h>
#include<string>
#include<iostream>
using namespace std;
char s[10000];

void build(int l, int r) {
  if(l == r) {
    if(s[l] == '1') {
      printf("I");
      return ;
    } else {
      printf("B");
      return ;
    }
  }

  int mid = l + r >> 1;
  build(l, mid);
  build(mid + 1,  r);


  int b = 1, i = 1;
  for(int j = l; j <= r ;j ++) {
    if(s[j] == '0') i = 0;
    else  b = 0;
  }
  if(i == 0 && b == 0) printf("F");
  else if(i == 0 && b == 1) printf("B");
  else if(i == 1 && b == 0) printf("I");

}

int main() {
  int n;
  scanf("%d", &n);
  n = pow(2, n);
  for(int i = 1;i <= n;i ++) {
      cin >> s[i];
  }
  build(1, n);
}