swust oj 972
统计利用先序遍历创建的二叉树的宽度
输入
输入为接受键盘输入的由大写英文字符和"#"字符构成的一个字符串(用于创建对应的二叉树)。
输出
输出该用例对应的二叉树的宽度。
样例输入
A##
ABC####
AB##C##
ABCD###EF##G###
A##B##
样例输出
1
1
2
3
1
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
typedef int Datetype;
using namespace std;
int x;
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 ;
} void wigth(tree *L,int ptr[],int i)
{
if(i<x&&L!=NULL)
{
ptr[i]++;
wigth(L->lchild,ptr,i+);
wigth(L->rchild,ptr,i+);
}
} int main()
{
tree *L = NULL;
int ptr[]={},max=;
creattree(L);
x=deep(L);
wigth(L,ptr,);
for(int i=;i<x;i++)
{
if(ptr[i]>max)
max=ptr[i];
}
cout<<max;
destroytree(L);
return ;
}
swust oj 972的更多相关文章
- [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 ...
随机推荐
- SpringBoot系列: Pebble模板引擎语法介绍
本文基于Pebble官方文档, 对pebble的语法做一些介绍. ===============================Pebble 官方资料========================= ...
- Vorticity directions 1: self-improving property of the vorticity
在 [Li, Siran. "On Vortex Alignment and Boundedness of $ L^ q $ Norm of Vorticity." arXiv p ...
- [物理学与PDEs]第4章第1节 引言
1. 本章讨论可燃流体在流动过程中同时伴随着燃烧现象的情况. 2. 燃烧有两种, 一种是爆燃 (deflagration): 火焰低速向前传播, 此时流体微元通常是未燃气体.已燃气体的混合物; 一 ...
- windows服务器基本管理及服务搭建
windows服务器基本管理及服务搭建 ****windows服务器系统版本:2000 2003 2008 2012 1.用户与组管理 用户:账户=账号/用户名+密码 每个账户有自己唯一的SID 账户 ...
- MySQL学习1 - 基本mysql语句
一 操作文件夹(数据库) 增 查 改 删 二 操作文件(数据表) 增 查 改 删 三 操作文件内容(数据记录) 增 查 改 删 一 操作文件夹(数据库) 增 create database db1 c ...
- hibernate之Session对象
Session对象:数据库的核心对象 增删改查 ...java public class UserDao { public void addUser(User user) { //使用hibernat ...
- windows下nginx的简单使用
在网上是可以查得到关于nginx的一些使用,每次要用的时候都会去查一下别人的用法.既然自己用到的频率会比较高,那何不自己做个小小的笔记呢. 我使用的是windows版nginx-1.14.0,版本对命 ...
- Java Queue之PriorityQueue
PriorityQueue位于Java util包中,观其名字前半部分的单词Priority是优先的意思,实际上这个队列就是具有“优先级”.既然具有优先级的特性,那么就得有个前后排序的“规则”.所以其 ...
- 【原创】大叔问题定位分享(8)提交spark任务报错 Caused by: java.lang.ClassNotFoundException: org.I0Itec.zkclient.exception.ZkNoNodeException
spark 2.1.1 一 问题重现 spark-submit --master local[*] --class app.package.AppClass --jars /jarpath/zkcli ...
- centos7端口永久开放方法
/sbin/iptables -I INPUT -p tcp --dport -j ACCEPT /sbin/iptables -I INPUT -p tcp --dport -j ACCEPT /s ...