[๋ฐฑ์ค-1991] ํธ๋ฆฌ ์ํ / Python
๐ Problem Solving/Baekjoon
1991๋ฒ: ํธ๋ฆฌ ์ํ
์ฒซ์งธ ์ค์๋ ์ด์ง ํธ๋ฆฌ์ ๋ ธ๋์ ๊ฐ์ N(1≤N≤26)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์ ๊ฑธ์ณ ๊ฐ ๋ ธ๋์ ๊ทธ์ ์ผ์ชฝ ์์ ๋ ธ๋, ์ค๋ฅธ์ชฝ ์์ ๋ ธ๋๊ฐ ์ฃผ์ด์ง๋ค. ๋ ธ๋์ ์ด๋ฆ์ A๋ถํฐ ์ฐจ๋ก๋๋ก ์๋ฌธ์
www.acmicpc.net
import sys
input = sys.stdin.readline
n = int(input())
tree = {}
for _ in range(n):
root, left, right = map(str, input().split())
tree[root] = [left, right]
def preorder(root):
if root != ".":
print(root, end="")
preorder(tree[root][0])
preorder(tree[root][1])
def inorder(root):
if root != ".":
inorder(tree[root][0])
print(root, end="")
inorder(tree[root][1])
def postorder(root):
if root != ".":
postorder(tree[root][0])
postorder(tree[root][1])
print(root, end="")
preorder("A")
print()
inorder("A")
print()
postorder("A")
ํด์ค
์ฌ๊ท ํจ์๋ก ํด๊ฒฐํ ์ ์๋ ๋ฌธ์ .
์ ์, ์ค์, ํ์ ์ํ ๋ณ๋ก ์ถ๋ ฅ ์์น๋ฅผ ๋ค๋ฅด๊ฒ ํด์ฃผ๋ฉด ๋๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-2407] ์กฐํฉ / Python (0) | 2021.06.01 |
---|---|
[๋ฐฑ์ค-1629] ๊ณฑ์ / Python (0) | 2021.06.01 |
[๋ฐฑ์ค-16236] ์๊ธฐ ์์ด / Python (0) | 2021.05.31 |
[๋ฐฑ์ค-14500] ํ ํธ๋ก๋ฏธ๋ ธ / Python (0) | 2021.05.31 |
[๋ฐฑ์ค-10026] ์ ๋ก์์ฝ / Python (0) | 2021.05.31 |