当前位置:网站首页>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;
}
边栏推荐
- opencv最大值滤波(不局限于图像)
- 520. detect capital letters
- 快慢指针系列
- KaFormer个人笔记整理
- 什么是图神经网络?图神经网络有什么用?
- À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL
- 所说的Get post:请求的区别,你真的知道了吗??????
- MBA-day25 最值问题-应用题
- 基于QingCloud的 “房地一体” 云解决方案
- Distributed | how to make "secret calls" with dble
猜你喜欢

What is the future development trend of Business Intelligence BI

The form image uploaded in chorme cannot view the binary image information of the request body

【量化投资】离散傅里叶变换求数组周期

华为路由器:GRE技术

KaFormer个人笔记整理

一文讲透,商业智能BI未来发展趋势如何

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

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL

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

Mysql数据(Liunx环境)定时备份
随机推荐
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
【Pytorch基础教程31】YoutubeDNN模型解析
数据中台:中台实践与总结
MySQL | 视图《康师傅MySQL从入门到高级》笔记
OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集
偶然间得到的framework工具类 自用
520. 检测大写字母
Fast and slow pointer series
1704. judge whether the two halves of a string are similar
[10 day SQL introduction] Day2
1704. 判断字符串的两半是否相似
【MySQL从入门到精通】【高级篇】(一)字符集的修改与底层原理
opencv最大值滤波(不局限于图像)
Database migration from PostgreSQL to MySQL
数据中台:民生银行的数据中台实践方案
leetcode 1268. Search suggestions system
1844. 将所有数字用字符替换
【牛客】HJ1 字符串最后一个单词的长度
MySQL | store notes of Master Kong MySQL from introduction to advanced
MySQL | view notes on Master Kong MySQL from introduction to advanced