菜鸟生成记(39)
思路: 构建二叉树,然后后序遍历(if套if)
#include<iostream>
using namespace std;
typedef struct st{
string x;
struct st *r,*l;
}ll,*link;
void create(link &t,string s)
{
if(s.length()<=1)
{
t->x=s;
t->l=t->r=NULL;
return;
}
else
{
string str;
t->l=new ll;
str=t->l->x=s.substr(0,s.length()/2);
create(t->l,str);
t->r=new ll;
str=t->r->x=s.substr(s.length()/2,s.length());
create(t->r,str);
}
}
void find1(string s)
{
int num1,num0;
num0=s.find("0");
num1=s.find("1");
if(num0!=-1&&num1==-1)
cout<<'B';
else if(num0==-1&&num1!=-1)
cout<<'I';
else
cout<<'F';
}
void input(link t)
{
if(t)
{
input(t->l);
input(t->r);
find1(t->x);
}
}
int main()
{
int n;
link t=new ll;
string s;
cin>>n;
cin>>s;
t->x=s;
create(t,s);
input(t);
return 0;
}