high函数好像出了问题。
#include<bits/stdc++.h>
using namespace std;
int n,pos=0;
char tree[1000010];
string s;
void buildtree(int r){
tree[r]=s[pos++];
if(tree[r]!='#'){
buildtree(2*r);
buildtree(2*r+1);
}
}
void inorder(int r){
if(tree[r]=='#')
return;
inorder(r*2);
cout<<tree[r];
inorder(r*2+1);
}
void beorder(int r){
if(tree[r]=='#')
return;
beorder(r*2);
beorder(r*2+1);
cout<<tree[r];
}
int leaf(int r){
if(tree[r]=='#')
return 0;
if(tree[r*2]=='#'&&tree[r*2+1]=='#')
return 1;
return leaf(r*2)+leaf(r*2+1);
}
int high(int r){
if(tree[r]=='#')
return 0;
if(tree[r*2]=='#'&&tree[r*2+1]=='#')
return 1;
return max(high(2*r),high(2*r+1)+1);
}
int main(){
cin>>s;
n=s.length();
buildtree(1);
inorder(1);
cout<<endl;
beorder(1);
cout<<endl;
cout<<leaf(1)<<endl;
cout<<high(1)<<endl;
return 0;
}