#include <iostream> #include<stdio.h> #include<algorithm> #include<malloc.h>
using namespace std; typedef struct node { int data; struct node *l,*r; }st; char s[10010]; int i; st *creat() { st *root; char ch; ch=s[i++]; if(ch==',') root=NULL; else { root=(st *)malloc(sizeof(st)); root->data=ch; root->l=creat(); root->r=creat(); } return root; } void zx(st *root) { if(root!=NULL) { zx(root->l); printf("%c",root->data); zx(root->r); } } void hx(st *root) { if(root!=NULL) { hx(root->l); hx(root->r); printf("%c",root->data);
} } int yz(st *root) { if(root==NULL) return 0; else if(root->l==NULL&&root->r==NULL) return 1; else return yz(root->l)+yz(root->r); } int sd(st *root) { int h,lh,rh; if(root==NULL) h=0; else { lh=sd(root->l); rh=sd(root->r); if(lh>=rh) h=lh+1; else h=rh+1; } return h; } int main() { st *root; int m=0,h=0; while(~scanf("%s",s)) { i=0; root=creat(); zx(root); cout<<endl; hx(root); cout<<endl; m=yz(root); cout<<m<<endl; h=sd(root); cout<<h<<endl; } }