#40668: 解答 python


n0970616056@gmail.com (CIOU-HE-CHEN)

學校 : 不指定學校
編號 : 273811
來源 : [111.253.1.171]
最後登入時間 :
2024-06-14 11:55:43
a349. 2. 指令解譯器 -- 100學年度北基區資訊學科能力競賽 | From: [27.247.62.29] | 發表日期 : 2024-06-04 22:07

# 初始化暫存器和主記憶體
registers = [0] * 4
memory = [0] * 8

# 讀入主記憶體初始值
for i in range(8):
    memory[i] = int(input())

# 讀入指令數量
N = int(input())

# 讀入並執行指令
for _ in range(N):
    instruction = input().split()
    cmd = instruction[0]
    
    if cmd == "LOAD":
        RD = int(instruction[1])
        MS = int(instruction[2])
        registers[RD] = memory[MS]
    elif cmd == "STORE":
        MD = int(instruction[1])
        RS = int(instruction[2])
        memory[MD] = registers[RS]
    elif cmd == "ADD":
        RD = int(instruction[1])
        RS1 = int(instruction[2])
        RS2 = int(instruction[3])
        registers[RD] = registers[RS1] + registers[RS2]
    elif cmd == "MOVE":
        RD = int(instruction[1])
        RS = int(instruction[2])
        registers[RD] = registers[RS]

# 輸出結果
print(registers[0])
print(memory[0])

 
ZeroJudge Forum