当前位置:网站首页>4274. suffix expression
4274. suffix expression
2022-06-24 08:56:00 【Ray. C.L】

Ideas : Build up trees , After the sequence traversal , Special judgment on minus sign
Code :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 30;
string v[N];
int st[N],l[N],r[N];
void dfs(int u){
cout << "(" ;
if(l[u] != -1 && r[u] != -1){
dfs(l[u]);
dfs(r[u]);
cout << v[u] ;
}else if(l[u] == -1 && r[u] == -1){
cout << v[u] ;
}else{
cout << v[u];
dfs(r[u]);
}
cout << ")";
}
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> v[i] >> l[i] >> r[i];
if(l[i] != -1) st[l[i]] = 1;
if(r[i] != -1) st[r[i]] = 1;
}
int root;
for(int i = 1; i <= n; i ++)
if(!st[i])
root = i;
dfs(root);
return 0;
}
边栏推荐
- 2022.06.23(LC_144,94,145_二叉树的前序、中序、后序遍历)
- leetcode 1268. Search suggestions system
- Deep learning and neural networks: the six most noteworthy trends
- 【牛客】把字符串转换成整数
- YOLOX backbone——CSPDarknet的实现
- Get screen width and height tool class
- 520. 检测大写字母
- 1844. replace all numbers with characters
- Mysql数据(Liunx环境)定时备份
- What is SRE? A detailed explanation of SRE operation and maintenance system
猜你喜欢

110. 平衡二叉树-递归法

A tip to read on Medium for free

Data middle office: detailed explanation of technical architecture of data middle office

【LeetCode】387. 字符串中的第一个唯一字符

K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream

4275. Dijkstra序列

China chip Unicorn Corporation

MBA-day25 最值问题-应用题

关于 GIN 的路由树

Matlab camera calibrator camera calibration
随机推荐
小程序wx.show
【NOI模拟赛】摆(线性代数,杜教筛)
GradScaler MaxClipGradScaler
【牛客】HJ1 字符串最后一个单词的长度
数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
A tip to read on Medium for free
Earthly 容器镜像构建工具 —— 筑梦之路
threejs辉光通道01(UnrealBloomPass && layers)
rpiplay实现树莓派AirPlay投屏器
A tip to read on Medium for free
所说的Get post:请求的区别,你真的知道了吗??????
工具类
ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
110. 平衡二叉树-递归法
4274. 后缀表达式
Why can ping fail while traceroute can
110. balanced binary tree recursive method
疫情、失业,2022,我们高喊着摆烂和躺平!
数据中台:数据中台全栈技术架构解析,附带行业解决方案
Fast and slow pointer series