当前位置:网站首页>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;
}
边栏推荐
- QT source code analysis -- QObject (2)
- 520. 检测大写字母
- Matlab camera calibrator camera calibration
- IDEA另起一行快捷键
- uniapp 开发多端项目如何配置环境变量以及区分环境打包
- MySQL——SQL语句
- 何时使用RDD和DataFrame/DataSet
- "Unusual proxy initial value setting is not supported", causes and Solutions
- Get screen width and height tool class
- 开源之夏中选名单已公示,基础软件领域成为今年的热门申请
猜你喜欢

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

KaFormer个人笔记整理

JS to find and update the specified value in the object through the key

2022.06.23(LC_144,94,145_二叉树的前序、中序、后序遍历)

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
![[quantitative investment] discrete Fourier transform to calculate array period](/img/0d/aac02463ff403fb1ff871af5ff91fa.png)
[quantitative investment] discrete Fourier transform to calculate array period

ZUCC_ Principles of compiling language and compilation_ Experiment 0607 grammar analysis ll analysis

It is enough to read this article about ETL. Three minutes will let you understand what ETL is

Prompt code when MySQL inserts Chinese data due to character set problems: 1366

A tip to read on Medium for free
随机推荐
Scheme of alcohol concentration tester based on single chip microcomputer
1844. replace all numbers with characters
One article explains in detail | those things about growth
MySQL | 存储《康师傅MySQL从入门到高级》笔记
基于单片机开发的酒精浓度测试仪方案
数据中台:中台架构及概述
基于QingCloud的地理信息企业研发云解决方案
The pie chart with dimension lines can set various parameter options
Data middle office: a collection of middle office construction architectures of large domestic factories
数据中台:中台实践与总结
A tip to read on Medium for free
工具类
leetcode 1268. Search suggestions system
用VNC Viewer的方式远程连接无需显示屏的树莓派
Liunx change the port number of vsftpd
Opencv maximum filtering (not limited to images)
關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
Data middle office: detailed explanation of technical architecture of data middle office
tcpdump抓包实现过程
520. detect capital letters