数据结构实验之二叉树三:统计叶子数

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

已知二叉树的一个按先序遍历输入的字符序列,如abc,,de,g,,f,,, (其中,表示空结点)。请建立二叉树并求二叉树的叶子结点个数。

Input

连续输入多组数据,每组数据输入一个长度小于50个字符的字符串。

Output

输出二叉树的叶子结点个数。

Sample Input

abc,,de,g,,f,,,

Sample Output

3
#include <stdio.h>
#include <stdlib.h>
#include <string.h> struct node
{
char c;
struct node *lt, *rt;
}; char s[100];
int i,k; struct node *creat()
{
struct node *root;
if(s[i]==','){
i++;
root=NULL;
}
else{
root=(struct node *)malloc(sizeof(struct node));
root->c=s[i++];
root->lt=creat();
root->rt=creat();
}
return root;
} void num(struct node *root)
{
if(root){
if(!root->lt&&!root->rt){
k++;
}
num(root->lt);
num(root->rt);
}
} int main()
{
while(~scanf("%s",s))
{
i=0;k=0;
struct node *root;
root=creat();
num(root);
printf("%d\n",k);
}
return 0;
}

SDUT OJ 数据结构实验之二叉树三:统计叶子数的更多相关文章

  1. SDUT 3342 数据结构实验之二叉树三:统计叶子数

    数据结构实验之二叉树三:统计叶子数 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知二叉 ...

  2. SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度

    数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...

  3. SDUT OJ 数据结构实验之二叉树七:叶子问题

    数据结构实验之二叉树七:叶子问题 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  4. SDUT OJ 数据结构实验之二叉树六:哈夫曼编码

    数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  5. SDUT OJ 数据结构实验之二叉树五:层序遍历

    数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  6. SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树

    数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...

  7. SDUT OJ 数据结构实验之二叉树二:遍历二叉树

    数据结构实验之二叉树二:遍历二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  8. SDUT OJ 数据结构实验之二叉树一:树的同构

    数据结构实验之二叉树一:树的同构 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  9. SDUT OJ 数据结构实验之串三:KMP应用

    数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

随机推荐

  1. c++builder 程序升级到c++builder10Seattle

    c++builder 程序升级到c++builder10Seattle的一些技巧提示. http://community.embarcadero.com/blogs/entry/migrating-l ...

  2. 微信小程序中出现Invoking Page() in async task.问题

    在做项目中需要让页面跳到外网,用到了<web-view src=""> </web-view>组件,需要新建一个文件放这个组件,调接口的时候链接连到这个页面 ...

  3. hibernate反向生成奇葩错误

    错误场景 最近搞一个hibernate的项目,由于好久不用hibernate了,稍微有点生疏(自从用了ibatis–>mybatis后).这个项目用了hibernate,和ibatis.myba ...

  4. SELINUX配置

    今天试着将centos7的ssh默认端口改成1234,但改了后,SSHD服务竟然启动不了了.后来关了selinux测试,果然可以了.但这是运行环境,不能关,所以不得不配置semanage! 一.安装s ...

  5. Spring总结十:事务案例

    数据库表Account: 导包: <dependencies> <!--测试--> <dependency> <groupId>junit</gr ...

  6. json_encode和json_decode和isset和array_key_exists

    1.json_decode() json_decode — 对 JSON 格式的字符串进行编码         说明 mixed json_decode ( string $json [, bool ...

  7. web优化

    一个小型的网站,可以使用最简单的html静态页面就实现了,配合一些图片达到美化效果,所有的页面均存放在一个目录下,这样的网站对系统架构.性能的要求都很简单.随着互联网业务的不断丰富,网站相关的技术经过 ...

  8. c# 获取客户端ip、mac、机器名、操作系统、浏览器信息

    d using System; using System.Collections.Generic; using System.Linq; using System.Web; using System. ...

  9. ESP8266-iot-简介1

    ESP8266简介

  10. 实践作业3:白盒测试---细化明确任务DAY5

    收到老师给我写的评论,感觉老师真的太认真,每个博客都有仔细的,参考了老师发给我的博客,我才明白老师想要的博客内容原来是具体实际的进展记录.我们组其实这些东西早就确定了,会议也开了,但是我之前不明白博客 ...