swust oj 971
统计利用先序遍历创建的二叉树的深度
输入
输入为先序遍历二叉树结点序列。
输出
对应的二叉树的深度。
样例输入
A##
ABC####
AB##C##
ABCD###E#F##G##
A##B##
样例输出
1
3
2
4
1
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
typedef int Datetype;
using namespace std;
typedef struct link{
Datetype date;
struct link *lchild;
struct link *rchild;
}tree; void creattree(tree *&L)
{
char c;
cin>>c;
if(c=='#')
L=NULL;
else
{
L = (tree *)malloc(sizeof(tree)) ;
L->date=c;
creattree(L->lchild);
creattree(L->rchild);
}
} void destroytree(tree *&L)
{
if(L!=NULL)
{
destroytree(L->lchild);
destroytree(L->rchild);
free(L);
}
} int deep(tree *L)
{
int ldep,rdep,max;
if(L!=NULL)
{
ldep=deep(L->lchild);
rdep=deep(L->rchild);
max=ldep>rdep?ldep+:rdep+;
return max;
}
else
return ;
} int main()
{
tree *L = NULL;
int x;
creattree(L);
x=deep(L);
cout<<x;
destroytree(L);
return ;
}
swust oj 971的更多相关文章
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)
题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...
- [Swust OJ 1026]--Egg pain's hzf
题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf ...
- [Swust OJ 1139]--Coin-row problem
题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...
- [Swust OJ 385]--自动写诗
题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535 Descripti ...
随机推荐
- [物理学与PDEs]第1章第8节 静电场和静磁场 8.1 静电场
1. 静电场: 由静止电荷产生的稳定电场. 2. 此时, Maxwell 方程组为 $$\bex \Div{\bf D}=\rho_f,\quad \rot{\bf E}={\bf 0}. \eex$ ...
- js打印WEB页面内容代码大全
第一种方法:指定不打印区域 使用CSS,定义一个.noprint的class,将不打印的内容放入这个class内. 详细如下: <style media=print type="tex ...
- idea一款颜值很高的theme
在idea的plugins搜索theme,能看到一款人气值超高的插件,下载使用了确实很漂亮!
- ActiveMQ的Destination高级特性
1. Composite Destinations 组合目的地 组合队列Composite Destinations : 允许用一个虚拟的destination代表多个destinations ...
- 3D Slicer中文教程(二)—软件功能界面介绍
1.界面介绍 2.菜单及工具栏介绍 (1)菜单 File-文件菜单 文件菜单包含用于加载MRML场景的选项,用于从互联网下载样本数据集或各种类型的各个数据集.此处还提供了保存场景和数据的选项. Edi ...
- Script error.解决方法
1. 添加 crossorigin="anonymous" 到script标签 <script src="https://xxx.com/xxx.js" ...
- selenium——find_element_by_xx 与 find_element(By.XX,'XXXX')
- LinkedList阅读
package java.util; import java.util.function.Consumer; public class LinkedList<E> extends Abst ...
- vue项目移植tinymce踩坑
转载:https://segmentfault.com/a/1190000012791569?utm_source=tag-newest 2019-2-18 貌似这篇文章帮了大家一些小忙最近tinym ...
- 末学者笔记--Linux计划任务及压缩归档
一.计划任务 1.介绍: (1)定义:简单说就是通过一些设置,来使linux系统定时执行一些操作与任务. (2)作用:一般可执行一些周期性操作,也可定期备份数据. (3)可使用的命令:常用为at和cr ...