#include <iostream>
#include <queue>
using namespace std;
typedef struct node {
char data;
struct node *lchild;
struct node *rchild;
} TNode;
TNode *CreateTree(TNode *&t);
int Count(TNode *t);
int R_Count(TNode *t);
int main() {
auto t = new TNode ;
CreateTree(t);
int num = R_Count(t);
cout<<num<<endl;
return 0;
}
TNode *CreateTree(TNode *&t) {
char c;
cin >> c;
if (c == '#')
t = nullptr;
else {
t = new TNode ;
t->data = c;
t->lchild = CreateTree(t->lchild);
t->rchild = CreateTree(t->rchild);
}
return t;
}
int Count(TNode *t){
queue <TNode *> q;
int flag = 0;
if (t->lchild!= nullptr&&t->rchild!= nullptr){
q.push(t);
}
TNode * p;
while (!q.empty()){
p = q.front();
q.pop();
if (p->lchild!= nullptr&&p->rchild!= nullptr){
flag+=1;
q.push(p->lchild);
q.push(p->rchild);
}
}
return flag+=1;
}
int R_Count(TNode *t){
if (t== nullptr)
return 0;
if (t->lchild== nullptr&&t->rchild== nullptr)
return 1;
return R_Count(t->lchild)+ R_Count(t->rchild);
}
|