Description
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!
-
Input
-
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.
-
Output
-
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 );}}