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.

54 lines
1.8 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
char s[1050];
/**
#本题主要考查树的遍历方法
1.
1
2.
3.FBIB101B0
I110I0BI0F
01
1
2
3)
4
*/
//递归建树
void buildTree(int x, int y){
if(y>x){
buildTree(x, (x + y) / 2); //这个左孩子的边界判定有意思
buildTree((x + y + 1) / 2, y); //这个右孩子的边界判定有意思
}
//不管x,y是不是一样都执行下面的代码,应该是后序的意思
int B=1,I=1; //是不是全是1或者全是0
for(int i=0;i<=y-x;i++){
if(s[x+i]=='1'){
B=0;
}else if(s[x+i]=='0'){
I=0;
}
}
//全是0输出B
if(B){
cout<<'B';
}else if(I){ //全是1输出I
cout<<'I';
}else{
//输出F,表示是混合的
cout<<'F';
}
}
int main() {
int n;
cin>>n>>s;
buildTree(0, (1 << n) - 1);
return 0;
}