当前位置:网站首页>4274. Suffix expression - binary expression tree
4274. Suffix expression - binary expression tree
2022-07-02 19:28:00 【linengcs】
- Postorder traversal of binary expression tree is suffix expression
- special case : How to distinguish positive signs from plus signs in expressions , What about minus signs and minus signs ?
answer : If a node is “+” or “-” Number , And its left subtree is empty , Then the symbol is positive ( negative ) Number , Not plus or minus , Then the node is traversed first rather than second
ACCode
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int t[N][2], vis[N];
int n;
string v[N];
void traverse(int node)
{
if (node == -1)
return;
if ((v[node] == "-" || v[node] == "+") && t[node][0] == -1)
{
cout << "(" << v[node];
traverse(t[node][1]);
cout << ")";
}
else
{
cout << "(";
traverse(t[node][0]);
traverse(t[node][1]);
cout << v[node];
cout << ")";
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> v[i] >> t[i][0] >> t[i][1];
if (t[i][0] != -1)
vis[t[i][0]] = 1;
if (t[i][1] != -1)
vis[t[i][1]] = 1;
}
int p;
for (int i = 1; i <= n; i++)
{
if (!vis[i])
{
p = i;
break;
}
}
traverse(p);
return 0;
}
边栏推荐
- Which video recording software is better for the computer
- [pytorch learning notes] tensor
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- 《重构:改善既有代码的设计》读书笔记(下)
- IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
- 预处理和预处理宏
- 《代码整洁之道》读书笔记
- 新手必看,点击两个按钮切换至不同的内容
- mybatiesHelperPro工具必须的可以生成到对应项目文件夹下
- 【测试开发】软件测试—概念篇
猜你喜欢

Talk about the design of red envelope activities in e-commerce system

9D电影是怎样的?(+维度空间常识)

Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5

Stm32g0 USB DFU upgrade verification error -2

Watchful pioneer world outlook Architecture - (how does a good game come from)

Develop fixed asset management system, what voice is used to develop fixed asset management system

高级性能测试系列《24. 通过jdbc执行sql脚本》

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统

PHP parser badminton reservation applet development requires online system
![[0701] [paper reading] allowing data imbalance issue with perforated input during influence](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
随机推荐
开发固定资产管理系统,开发固定资产管理系统用什么语音
仿京东放大镜效果(pink老师版)
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
数字滚动带动画
Notes de lecture sur le code propre
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
Golang:[]byte to string
Develop fixed asset management system, what voice is used to develop fixed asset management system
Usage of ieda refactor
数据降维——因子分析
Gamefi链游系统开发(NFT链游开发功能)丨NFT链游系统开发(Gamefi链游开发源码)
A4988 drive stepper motor "recommended collection"
IEDA refactor的用法
452-strcpy、strcat、strcmp、strstr、strchr的实现
【pytorch学习笔记】Tensor
SIFT feature point extraction "suggestions collection"
What is 9D movie like? (+ common sense of dimension space)
虚拟机初始化脚本, 虚拟机相互免秘钥
MySQL