#include
#include <bits/stdc++.h>
using namespace std;
char a[55];
int s=0;
int sum;
struct node
{
char data;
struct node *l,*r;
};
struct node *creat()
{
struct node root;
char c;
c=a[s++];
if(c==’,’)
root=NULL;
else
{
root=(struct node)malloc(sizeof(struct node));
root->data=c;
if(root)
{
root->l=creat();
root->r=creat();
}
}
return root;
};
int yezi(struct node *root)
{
if(rootNULL)
return 0;
if(root->lNULL&&root->r==NULL)
return 1;
else
return yezi(root->l)+yezi(root->r);
}
int main()
{
struct node *root;
while(~scanf("%s",a))
{
s=0;
root=creat();
sum=yezi(root);
printf("%d\n",sum);
}
return 0;
}
来源:CSDN
作者:郇正达
链接:https://blog.csdn.net/huanzhngda/article/details/104694510