当前位置:网站首页>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;
}
边栏推荐
- Idea another line shortcut
- 华为路由器:ipsec技术
- 1528. 重新排列字符串
- Data middle office: detailed explanation of technical architecture of data middle office
- MySQL——SQL语句
- leetcode——错误的集合
- 开源之夏中选名单已公示,基础软件领域成为今年的热门申请
- 【PyTorch基础教程30】DSSM双塔模型代码解析
- Database migration from PostgreSQL to MySQL
- One article explains in detail | those things about growth
猜你喜欢
随机推荐
uniapp 开发多端项目如何配置环境变量以及区分环境打包
"Unusual proxy initial value setting is not supported", causes and Solutions
every()、map()、forEarch()方法。数组里面有对象的情况
[quantitative investment] discrete Fourier transform to calculate array period
MySQL | store notes of Master Kong MySQL from introduction to advanced
【使用 PicGo+腾讯云对象存储COS 作为图床】
K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
1528. rearrange strings
解决:模型训练时loss出现nan
第七章 操作位和位串(三)
随笔-反思
110. balanced binary tree recursive method
双指针模拟
GradScaler MaxClipGradScaler
Data middle office: detailed explanation of technical architecture of data middle office
【MySQL从入门到精通】【高级篇】(一)字符集的修改与底层原理
工具类
Database to query the quantity of books lent in this month. If it is higher than 10, it will display "more than 10 books lent in this month". Otherwise, it will display "less than 10 books lent in thi
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍








