n = int(input())
f = [[] for _ in range(100)]
for _ in range(n):
p,lc,rc = map(ord,input().split())
f[p].append(lc)
f[p].append(rc)
def preorder(x):
print(chr(x),end='')
for next in f[x]:
if next == 46:
continue
preorder(next)
def inorder(x):
lc,rc = f[x]
if lc != 46:
inorder(lc)
print(chr(x),end='')
if rc != 46:
inorder(rc)
def postorder(x):
for next in f[x]:
if next == 46:
continue
postorder(next)
print(chr(x),end='')
preorder(65)
print()
inorder(65)
print()
postorder(65)
print()
ord, chr를 활용해 더럽게 풀어보았다.
'BOJ' 카테고리의 다른 글
| <15989번> 1,2,3 더하기 4 (0) | 2022.01.13 |
|---|---|
| <11060번> 점프 점프 (0) | 2022.01.13 |
| <11048번> 이동하기 (0) | 2022.01.13 |
| <2580번> 스도쿠 (0) | 2022.01.08 |
| <16197번> 두 동전 (0) | 2022.01.07 |