🔻PS/Programmers

[Programmers] 프로그래머스 비밀지도 Python

_니지 2024. 5. 14. 23:44

https://school.programmers.co.kr/learn/courses/30/lessons/17681

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

def solution(n, arr1, arr2):
    arr1_map = []
    arr2_map = []
    result = []
    
    # 2진수
    def binary(num):
        b = ''
        while num > 0:
            b = str(num%2) + b 
            num //= 2
        
        if len(b) < n:
            for _ in range(n - len(b)):
                b = '0' + b
        return b
    
    
    # 구현부
    for e in arr1:
        arr1_map.append(binary(e))
    
    for e in arr2:
        arr2_map.append(binary(e))
    
    for a, b in zip(arr1_map, arr2_map):
        temp = ''
        
        for i in range(n):
            if a[i] == '0' and b[i] == '0':
                temp += " "
            else:
                temp += "#"
        
        result.append(temp)
    
    
    return result
728x90
반응형