POJ-1577-Falling Leaves
来源:互联网 发布:视频监控软件界面设计 编辑:程序博客网 时间:2024/06/05 03:20
二叉树的基本练习题,比较简单吧,只是对输入数据处理以及对树的建立注意下就可以了。
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;struct node{ int lchild; int rchild; char val;}t[1000];char str[1000];int n;void Add(int index,char val){ if(t[index].val==0) {t[index].val=val;return ; } else if(t[index].val<val) {if(!t[index].rchild) t[index].rchild=n++;Add(t[index].rchild,val); } else {if(!t[index].lchild) t[index].lchild=n++;Add(t[index].lchild,val); }}void DisplayTree(int index){ if(t[index].val==0)return; printf("%c",t[index].val); if(t[index].lchild)DisplayTree(t[index].lchild); if(t[index].rchild)DisplayTree(t[index].rchild);}int main(){ while(scanf("%s",str)!=EOF) {int len=strlen(str);char ch;n=2;memset(t,0,sizeof(t));while(1){ scanf("%c",&ch); if(ch>='A'&&ch<='Z')str[len++]=ch; else if(ch=='*'||ch=='$')break;}for(int i=len-1;i>=0;i--) Add(1,str[i]);DisplayTree(1);printf("\n");if(ch=='$') break; } return 0;}
- POJ-1577-Falling Leaves
- POJ 1577 Falling Leaves
- POJ 1577 Falling Leaves
- poj 1577 Falling Leaves
- POJ 1577 Falling Leaves
- poj 1577 Falling Leaves
- zoj 1700 || poj 1577 Falling Leaves(BST)
- poj 1577 Falling Leaves
- 二叉树 Poj 1577 Falling Leaves
- POJ 1577 Falling Leaves 二叉树题解
- poj-1577 Falling Leaves(搜索二叉树)
- POJ 1577 Falling Leaves 二叉树操作
- POJ 1577 Falling Leaves 二叉树
- poj 1577 Falling Leaves(二叉搜索树)
- PKU 1577 Falling Leaves
- zoj 1700 || poj 1577 Falling Leaves(BST应用)
- POJ 1577 Falling Leaves(二叉搜索树)
- POJ 1577 Falling leaves (二叉树的构造)
- 错误: 聚合‘QDateTime time’类型不完全,无法被定义
- Ubuntu apt-cache命令查找可用软件包
- 例题
- Kinect for Windows Samples
- vmware tools怎么安装
- POJ-1577-Falling Leaves
- rails项目css文件加载不成功
- 在Android项目中创建一个包含main()方法的类,直接右键运行该类时会报如下错误:ShouldNotReachHere()
- EditText输入是否为空,限定输入数字的实现
- jquery.fn.extend与jquery.extend
- 模态对话框调用及值传递
- 2.52
- C# 操作Word批量替换
- 类与职工工资