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 ...
随机推荐
- Selenium with Python 002 - 快速入门
一.简单实例演示 1.创建 python_org_search.py: #!/usr/bin/env python from selenium import webdriver from seleni ...
- sed、awk学习篇
[yongsan@yz6245 ~]$ awk 'BEGIN {FS=":"}{shells[$NF]++;}END{for(i in shells)print i ": ...
- 【JAVA】IOS内购二次验证及掉单问题解决
这个估计是我踩过的最大的坑,当时做微信支付的时候也没这么坑爹,当然他俩也半斤八两... 苹果官方明确表示:验证支付时,可能会有一定的延迟.第一次处理的时间就专注的解决这个问题了,忽略了掉单的问题(稍后 ...
- Swagger实践和总结
Swagger学习和实践 最近安装并使用了一下Swagger-ui.Swagger-editor和Swagger-codegen,感觉还不错. Swagger 是一个规范和完整的框架,用于生成.描述. ...
- Integer类分析(jdk8)
一.构造函数 1. Integer类继承Number类,实现Comparable接口,重写了compareTo()方法. 2. Integer最小值为-2147483648,最大值为214748364 ...
- CSS: The resize Property
用户手动调节输入框样式: <!DOCTYPE html> <html> <head> <style> div { border: 2px solid; ...
- react-router-dom: 重定向默认路由
<appLayout> <Switch> <Route path='/' exact render={()=> ( <Redirect to={this.ge ...
- New Concept English three (32)
26w/m 68 The salvage operation had been a complete failure. The small ship, Elkor, which had been se ...
- 【SQL查询】日期的转换_to_date/to_char
1. 日期转换为字符 select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual; 2. 字符转换为日期 select to_date('200 ...
- requestAnimationFrame 与 cancelAnimationFrame
API接口 Window对象定义了以下两个接口: partial interface Window { long requestAnimationFrame(FrameRequestCallback ...