输入
接受键盘输入的由大写英文字符和"#"字符构成的一个字符串(用于创建对应的二叉树)。
输出
输出该用例对应的二叉树度为2的结点个数。
样例输入复制
# A## ABC#### AB##C## ABCD###EF##G##H## A##B## #A
样例输出复制
0 0 0 1 3 0 0
#include#include using namespace std; typedef struct BitNode{ char data; struct BitNode *lc,*rc; }BitNode,*BitTree; void CreateBitTree(BitTree &T){ char ch; cin >> ch; if(ch!='#'){ T = (BitTree)malloc(sizeof(BitNode)); T->data = ch; CreateBitTree(T->lc); CreateBitTree(T->rc); }else T = NULL; } int n=0; int VisitBitTree(BitTree T){ if(T!=NULL){ if(T->lc!=NULL&&T->rc!=NULL) //度为二的节点,左右指针不为空 n++; VisitBitTree(T->lc); VisitBitTree(T->rc); } return n; } int main(){ BitTree T = NULL; CreateBitTree(T); cout << VisitBitTree(T); return 0; }



