BOJ - 16506 - CPU

Updated:

import sys

CPU = {
    "ADD": 0, "ADDC": 1, "SUB": 2, "SUBC": 3,
    "MOV": 4, "MOVC": 5, "AND": 6, "ANDC": 7,
    "OR": 8, "ORC": 9, "NOT": 10, "MULT": 12,
    "MULTC": 13, "LSFTL": 14, "LSFTLC": 15, "LSFTR": 16,
    "LSFTRC": 17, "ASFTR": 18, "ASFTRC": 19, "RL": 20,
    "RLC": 21, "RR": 22, "RRC": 23
}

def solution():
    N = int(input())

    for _ in range(N):
        ret = ""
        arr = list(map(str, sys.stdin.readline().split()))

        code = arr[0]
        ret += str(bin(CPU[code])[2:].zfill(5)) + '0'
        ret += str(bin(int(arr[1]))[2:].zfill(3))
        ret += str(bin(int(arr[2]))[2:].zfill(3))

        if code[-1] == 'C':
            ret += str(bin(int(arr[3]))[2:].zfill(4))
        else:
            ret += str(bin(int(arr[3]))[2:].zfill(3)) + '0'

        print(ret)
solution()

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

Categories:

Updated:

Leave a comment