You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
string s; //2^n长度的01串
/**
* s
* @param s
* @return
*/
char getStype(string s) {
int c0 = 0, c1 = 0;
for (int i = 0; i < s.size(); i++) if (s[i] == '1') c1++; else c0++;
if (c1 == 0)return 'B';
else if (c0 == 0) return 'I';
return 'F';
}
/**
* FBI
* @param start
* @param end
*/
void dfs(string s) {
if (s.length() > 1) {
//左树
dfs(s.substr(0, s.length() / 2));//从哪个位置开始,截取多少个
//右树
dfs(s.substr(s.length() / 2));//从哪个位置开始,不说截取多少个就是截取到尾
}
cout << getStype(s);//后序遍历
}
int main() {
//这个n是无用的因为是上古的考题都是C时代的要求使用char数组没有n说不过去现在都用string了不需要n了。
cin >> n >> s;
//利用递归构建FBI树
dfs(s);
return 0;
}