981 统计利用二叉树存储的森林中树的棵数
(左儿子,右兄弟)
http://acm.swust.edu.cn/#/problems/981/271
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
char data;
struct node *lchild;
struct node *rchild;
}btTree;
int t=0;
btTree* creatTree(char *p)
{
btTree *bt = NULL;
char temp = p[t++];
if(temp!=’#’)
{
bt=(btTree *)malloc(sizeof(btTree));
bt->data=temp;
bt->lchild=creatTree§;
bt->rchild=creatTree§;
}
return bt;
}
int count=0;
void fun(btTree *&bt)
{
if(bt==NULL)
{
return;
}
count++;
fun(bt->rchild);//只遍历右边
}
int main()
{
btTree *bt;
char s[100];
while(~scanf("%s",s))
{
if(s[0]==‘0’)
{
return 0;
}
else
{
char *p=s;
t=0;
count=0;
bt=creatTree§;
fun(bt);
printf("%d",count);
}
}
return 0;
}