๐ฆ ๐ ๊ท๋ ๋ฐ ๋ก์ธ์ ํฌ๋ฆฌ์ค๋ง์ค๋ ์ฌ์ฌํ๋ค๊ณ ํ์ด์ฌ์ ๋ง๋ค์๋ค
1. ๋ฌธ์ ๋งํฌ
6568๋ฒ: ๊ท๋ ๋ฐ ๋ก์ธ์ ํฌ๋ฆฌ์ค๋ง์ค๋ ์ฌ์ฌํ๋ค๊ณ ํ์ด์ฌ์ ๋ง๋ค์๋ค
2. ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
PC = 0
ADD = 0
MEM = [0] * 32
while True:
try:
inp = input()
command = inp[:3]
mem = inp[3:8]
# ๋ช
๋ น์ด ์คํ ์ PC ์ฆ๊ฐ
PC += 1
if command == '000': # ๊ฐ์ฐ๊ธฐ์ ์ ์ฅ
address = int(mem, 2)
MEM[address] = ADD
elif command == '001': # ๊ฐ์ฐ๊ธฐ๋ก ๋ถ๋ฌ์ด
address = int(mem, 2)
ADD = MEM[address]
elif command == '010': # ๊ฐ์ฐ๊ธฐ๊ฐ 0์ด๋ฉด PC์ mem ์ ์ฅ
if ADD == 0:
address = int(mem, 2)
PC = MEM[address]
elif command == '011': # nop
continue
elif command == '100': # ๊ฐ์ฐ๊ธฐ --
ADD -= 1
elif command == '101': # ๊ฐ์ฐ๊ธฐ ++
ADD += 1
elif command == '110': # PC ๋ฅผ x๋ก ๋ฐ๊พผ๋ค
address = int(mem, 2)
PC = MEM[address]
elif command == '111': # ์ข
๋ฃ
continue
except:
break # EOF
# print(int(ADD, 2))
binary_string = format(ADD, 'b')
binary_string = binary_string.zfill(8)
print(binary_string)
This post is licensed under CC BY 4.0 by the author.