level 11
歆沣
楼主
//后序遍历FBI树,递归形式
#include<iostream>
#include<string>
using namespace std;
string str;//01串
string ss="";//后序遍历结果 void fun(int s,int e){
if(e==s+1){
if(str[s]=='0')ss+='B';
if(str[s]=='1')ss+='I';
return;
}
fun(s,(e+1+s)/2);
fun((e+1+s)/2,e);
bool b=0,i=0;
for(int j=s;j<e;j++){
if(str[j]=='0')b=1;
if(str[j]=='1')i=1;
}
if(b){
if(i){
ss+='F';
}else{
ss+='B';
}
}else{
if(i){
ss+='I';
}
}
}int main(){
cin>>str;
fun(0,str.length());
cout<<ss<<endl;
}
傲世孤尘
2013-05-31
2013年07月22日 14点07分
1
#include<iostream>
#include<string>
using namespace std;
string str;//01串
string ss="";//后序遍历结果 void fun(int s,int e){
if(e==s+1){
if(str[s]=='0')ss+='B';
if(str[s]=='1')ss+='I';
return;
}
fun(s,(e+1+s)/2);
fun((e+1+s)/2,e);
bool b=0,i=0;
for(int j=s;j<e;j++){
if(str[j]=='0')b=1;
if(str[j]=='1')i=1;
}
if(b){
if(i){
ss+='F';
}else{
ss+='B';
}
}else{
if(i){
ss+='I';
}
}
}int main(){
cin>>str;
fun(0,str.length());
cout<<ss<<endl;
}
傲世孤尘
2013-05-31