t = int(input())
dict_hexa = {
'0':[0,0,0,0],
'1':[0,0,0,1], # 1
'2':[0,0,1,0], # 2
'3':[0,0,1,1], # 3
'4':[0,1,0,0], # 4
'5':[0,1,0,1], # 5
'6':[0,1,1,0], # 6
'7':[0,1,1,1], # 7
'8':[1,0,0,0], # 8
'9':[1,0,0,1], # 9
'A':[1,0,1,0], # 10(A)
'B':[1,0,1,1], # 11(B)
'C':[1,1,0,0], # 12(C)
'D':[1,1,0,1], # 13(D)
'E':[1,1,1,0], # 14(E)
'F':[1,1,1,1],
}
for tc in range(1,t+1):
n, n16 = map(str,input().split())
# print(n16)
new_str = []
for item in n16:
new_str += dict_hexa[item]
# print(new_str)
print(f"#{tc} {''.join(map(str,new_str))}")
딕셔너리의 value에 리스트로 두지말고 str로 두는게 나았을것 같다.
hexa = {
'0':'0000', '1':'0001', '2':'0010', '3':'0011', '4':'0100', '5':'0101',
'6':'0110', '7':'0111', '8':'1000', '9':'1001', 'A':'1010', 'B':'1011',
'C':'1100', 'D':'1101', 'E':'1110', 'F':'1111'
}
t = int(input())
for tc in range(1,t+1):
n, n16 = map(str,input().split())
new_str = ''
for i in n16:
new_str += hexa[i]
print(new_str)
'알고리즘 문제풀이' 카테고리의 다른 글
Swea D2_ 11927. 이진탐색 Python Tree (0) | 2024.02.23 |
---|---|
Swea D3_1240.단순 2진 암호코드 Python (0) | 2024.02.23 |
Swea D3_11753. 이진수2 Python 2진법 (0) | 2024.02.22 |
백준 1620. 나는야 포켓몬 마스터 이다솜 Python 실버4 (1) | 2024.02.21 |
baekjoon No Duplicates Bronze 1 (0) | 2024.02.21 |