Sdut 3342 Data structure Experiment two forks Tree Three: Statistics leaf number

Source: Internet
Author: User

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-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.