Data structure Experiment two forks Tree Three: Statistics leaf number time limit:1000ms Memory limit:65536kbsubmit Statisticproblem Description
A sequence of characters of a binary tree that is known to iterate through the input, such as a abc,,de,g,,f,,, (which represents an empty node). Please establish a two-fork tree and find the number of leaf nodes of the binary tree.
Input
Enter multiple sets of data consecutively, with each set of data entering a string of less than 50 characters in length.
Output
The number of leaf nodes of the output binary tree.
Example Input
Abc,,de,g,,f,,,
Example Output
3
DQE:Water problem together.
1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 structTree7 {8 CharC;9Tree *lt,*RT;Ten }; One ATree *creat (Char*&xx) - { - if(*xx==' /') the returnNULL; - if(*xx==',') - { -xx++; + returnNULL; - } +Tree *r=NewTree; Ar->c=*xx++; atr->lt=creat (xx); -r->rt=creat (xx); - returnR; - } - - intVisit (Tree *R) in { - if(r==NULL) to return 0; + if(r->lt==null&&r->rt==NULL) - return 1; the returnVisit (R->LT) +visit (r->RT); * } $ Panax Notoginseng intMain () - { theTree *Root; + Charxx[ -],*p; A while(SCANF ("%s", XX)! =EOF) the { +p=xx; -root=creat (p); $printf"%d\n", visit (Root)); $ } - return 0; - } the - /***************************************************Wuyi User Name: * * * the result:accepted - Take time:0ms Wu Take memory:160kb - Submit time:2016-11-03 18:21:59 About ****************************************************/
Sdut 3342 Data structure Experiment two forks Tree Three: Statistics leaf number