1398 number of trees and leaf nodes

Source: Internet
Author: User

A generalized table representation of a binary tree is provided. Use a binary linked list to create a binary tree. And output the number of leaf nodes in the tree. (5)

No empty tree is considered!


The input contains N + 1 rows. The number of groups of the first behavior test data is N, And the next n behavior is the Binary Tree represented by the generalized table representation of N Binary Trees. The element in the tree is Char.


There are n rows in the input, which correspond to the number of leaf nodes of N Binary Trees.



Solve with parentheses

# Include <stdio. h> main () {int number, Te; char a [1000]; int I; int count; scanf ("% d", & number); For (TE = 1; te <= number; Te ++) {scanf ("% s", & A); Count = 0; for (I = 0; A [I]! = '\ 0'; I ++) {if (a [I]! = '(' & A [I]! = ')' & A [I]! = ',') Count ++; if (a [I] = '(') count --;} printf ("% d \ n", count );}}


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.