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 ...
随机推荐
- Spring Security 之基本概念
Spring Security 是一个安全框架, 可以简单地认为 Spring Security 是放在用户和 Spring 应用之间的一个安全屏障, 每一个 web 请求都先要经过 Spring S ...
- 五十、进程间通信——System V IPC 之共享内存
50.1 共享内存 50.1.1 共享内存的概念 共享内存区域是被多个进程共享的一部分物理内存 多个进程都可把该共享内存映射到自己的虚拟内存空间.所有用户空间的进程若要操作共享内存,都要将其映射到自己 ...
- slot
本文涉及的slot有:<slot>,v-slot吗,vm.$slots,vm.$scopedSlots 废弃的使用特性:slot,slot-scope,scope(使用v-slot,2.6 ...
- BootStrap分页教程
https://www.cnblogs.com/laowangc/p/8875526.html https://www.cnblogs.com/yinglunstory/p/6092834.html ...
- java获取当前运行的方法名称
// 这种方式获取的话,数组的第一个元素是当前运行方法的名称,第二个元素是调用当前方法的方法名称 StackTraceElement[] stackTrace = new Exception().ge ...
- SecureCRT的安装与破解(过程很详细!!!)
SecureCRT的安装与破解(过程很详细!!!) 使用SecureCRT可以方便用户在windows环境下对linux主机进行管理,这里为大家讲一下SecureCRT的破解方法,仅供大家参考学习: ...
- 【原创】运维基础之Nginx(1)简介、安装、使用
官方:http://nginx.org nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a ...
- vue-cli 打包编译 -webkit-box-orient: vertical 被删除解决办法
前言 -webkit-box-orient: vertical在本地开发环境运行都没问题,一旦打包以后就会丢失 正文 原因: -webkit-box-orient: vertical 这个属性被 o ...
- 著名的3像素Bug(div+img,多出几像素)
<div><img src="...."></div> 给img的css设置display: block;/*用来去除div下边莫名多出来的3p ...
- 删除倒数第k个元素
给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 ...