#include<stdio.h>
#include<stdlib.h>
typedef struct tree
{
char c;
struct tree *l,*r;
}t,*lt;
char s[1010];
int i=0,shen,mshen;
lt h;
lt sol()
{
lt cur=(lt)malloc(sizeof(t));
cur->c=s[i++];
if(cur->c=='1')
{
free(cur);
return NULL;
}
shen++;
if(shen>mshen)
mshen=shen;
cur->l=sol();
cur->r=sol();
shen--;
return cur;
}
void ye(lt p)
{
if(p->l==NULL&&p->r==NULL)
printf("%c ",p->c);
if(p->l!=NULL)
ye(p->l);
if(p->r!=NULL)
ye(p->r);
}
int main()
{
while(gets(s))
{
shen=0;
mshen=0;
i=0;
h=sol();
printf("%d\n",mshen);
ye(h);
printf("\n");
}
return 0;
}
zzuli 1209 二叉树(2)
最新推荐文章于 2023-11-26 12:01:58 发布