当前位置:网站首页>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;
}
边栏推荐
- ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis
- 数组相向指针系列
- Data midrange: detailed explanation of the technical stack of data acquisition and extraction
- Picture tools
- 1844. 将所有数字用字符替换
- [pytoch basic tutorial 31] youtubednn model analysis
- WebRTC系列-网络传输之5选择最优connection切换
- Scheme of alcohol concentration tester based on single chip microcomputer
- leetcode 1268. Search suggestions system
- Background management of uniapp hot update
猜你喜欢

A tip to read on Medium for free

华为路由器:GRE技术

"Unusual proxy initial value setting is not supported", causes and Solutions

疫情、失业,2022,我们高喊着摆烂和躺平!

Background management of uniapp hot update

【牛客】HJ1 字符串最后一个单词的长度

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5

Xiaohei ai4code code baseline nibble 1
![Jenkins is deployed automatically and cannot connect to the dependent service [solved]](/img/fe/f294955a9bdf7492aab360e44e052d.png)
Jenkins is deployed automatically and cannot connect to the dependent service [solved]

Qingcloud based "real estate integration" cloud solution
随机推荐
打印出来的对象是[object object],解决方法
等保备案是什么意思?应该去哪里办理备案?
What is the future development trend of Business Intelligence BI
Data middle office: overview of data governance
xargs使用技巧 —— 筑梦之路
陆奇:我现在最看好这四大技术趋势
常用表情符号
Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
Jenkins is deployed automatically and cannot connect to the dependent service [solved]
Opencv maximum filtering (not limited to images)
關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
Liunx change the port number of vsftpd
Data midrange: detailed explanation of the technical stack of data acquisition and extraction
110. 平衡二叉树-递归法
The form image uploaded in chorme cannot view the binary image information of the request body
GradScaler MaxClipGradScaler
every()、map()、forEarch()方法。数组里面有对象的情况
Data middle office: middle office architecture and overview
1704. 判断字符串的两半是否相似
数据中台:数据治理概述