본문 바로가기

백준

[백준] 16506번: CPU(파이썬)

https://www.acmicpc.net/problem/16506

 

구현 문제여서 노가다성 문제인듯하다

num = int(input())
opcode_machine = {'ADD':'0000', 'SUB':'0001', 'MOV':'0010', 'AND':'0011','OR':'0100',
                   'NOT':'0101','MULT':'0110', 'LSFTL':'0111', 'LSFTR':'1000',
                   'ASFTR':'1001','RL':'1010','RR':'1011'}

for i in range(num):
    opcode, x, y, z = input().split()
    result = ''
    
    if opcode[-1]=='C':
        result += opcode_machine.get(opcode[:-1])
        result += '1'
    else:
        result += opcode_machine.get(opcode)
        result += '0'
    result += '0'

    result += str(bin(int(x)))[2:].zfill(3)
    result += str(bin(int(y)))[2:].zfill(3)

    if result[4]=='0':
        result+=str(bin(int(z)))[2:].zfill(3)
        result+='0'
    else:
        result+=str(bin(int(z)))[2:].zfill(4)
    
    print(result)