1130 Infix Expression
题意:给出一个语法树(二叉树),输出相应的中缀表达式。
思路:很显然,通过中序遍历来做。通过观察,发现除了根结点之外的所有非叶结点的两侧都要输出括号,故在中序遍历时判断一下即可。
代码:
#include <cstdio>
#include <cstring>
struct Node{
];
int left,right;
}Tree[];
;//根结点
void inOrderTraversal(int v)
{
){
|| Tree[v].right!=-)) printf("(");
inOrderTraversal(Tree[v].left);
printf("%s",Tree[v].data);
inOrderTraversal(Tree[v].right);
|| Tree[v].right!=-)) printf(")");
}
}
int main()
{
];
memset(isRoot,true,sizeof(isRoot));
int n;
scanf("%d",&n);
;i<=n;i++){
scanf("%s %d %d",Tree[i].data,&Tree[i].left,&Tree[i].right);
) isRoot[Tree[i].left]=false;
) isRoot[Tree[i].right]=false;
}
while(isRoot[root]==false) root++;
inOrderTraversal(root);
;
}
1130 Infix Expression的更多相关文章
- PAT甲级 1130. Infix Expression (25)
1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...
- PAT 1130 Infix Expression[难][dfs]
1130 Infix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspond ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- PAT 甲级 1130 Infix Expression
https://pintia.cn/problem-sets/994805342720868352/problems/994805347921805312 Given a syntax tree (b ...
- PAT 1130 Infix Expression
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...
- 1130. Infix Expression (25)
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...
- PAT甲题题解-1130. Infix Expression (25)-中序遍历
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT1130:Infix Expression
1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...
- A1130. Infix Expression
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...
随机推荐
- [日常训练]Z国特色社会路
Description 小$W$非常喜欢社会主义,这天他开始研究它的优越性. 他发现它们国家十分乐于修建特色的社会主义道路.具体的说,$Z$国有$n$座城市,由$m$条有向边连接,城市从$1$编号. ...
- HDU-4510-日期
http://acm.hdu.edu.cn/showproblem.php?pid=4510 小Q系列故事——为什么时光不能倒流 Time Limit: 300/100 MS (Java/Others ...
- python tesseract-ocr 基础验证码识别功能(Windows)
一.环境 windows 7 x64 Python 3 + 二.安装 1.tesseract-ocr安装 http://digi.bib.uni-mannheim.de/tesseract/ 2.py ...
- java mybatis XML文件中大于号小于号转义(转载)
因为这个是xml文件不允许出现类似“>”这样的字符 用了转义字符把>和<替换掉,然后就没有问题了. XML转义字符 字段 符号 说明 < ; < 小于号 & ...
- HData——ETL 数据导入/导出工具
HData是一个异构的ETL数据导入/导出工具,致力于使用一个工具解决不同数据源(JDBC.Hive.HDFS.HBase.MongoDB.FTP.Http.CSV.Excel.Kafka等)之间数据 ...
- SpringMVC札集(01)——SpringMVC入门完整详细示例(上)
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...
- MAC版画图软件 paintbrush 推荐,类似 windows 上系统自带的画图软件
不想开photoshop这么重的软件,但是对于屏幕截图有需要有一点处理.这时候我想起 windows上画图的好了. 搜索了一下,知道了 paintbrush 这个软件,于是下载试用了一下,果然很好. ...
- tf随笔-5
# -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf. ...
- Linux paste 命令
Linux paste命令用于合并文件的列. paste指令会把每个文件以列对列的方式,一列列地加以合并. 语法 paste [-s][-d <间隔字符>][--help][--versi ...
- linux下安装boost
linux平台下要编译安装除gcc和gcc-c++之外,还需要两个开发库:bzip2-devel 和python-devel,因此在安装前应该先保证这两个库已经安装:#yum install gcc ...