ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

[1차] 비밀지도 #251

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image image image

ji-0630 commented 1 year ago

나의 풀이

def solution(n, arr1, arr2):
    answer = []

    new_arr1 = list(map(lambda x: bin(x)[2:] if len(bin(x))-2 == n else ("0"*(n+2-len(bin(x))) + bin(x)[2:]) , arr1))
    new_arr2 = list(map(lambda x: bin(x)[2:] if len(bin(x))-2 == n else ("0"*(n+2-len(bin(x))) + bin(x)[2:]) , arr2))

    for i in range(n):
        s = ""
        for j in range(n):
            if (new_arr1[i][j] == "0") & (new_arr2[i][j] == "0"):
                s += " "
            else:
                s += "#"
        answer.append(s)

    return answer
ji-0630 commented 1 year ago

다른 사람의 풀이

def solution(n, arr1, arr2):
    answer = []
    for i,j in zip(arr1,arr2):
        a12 = str(bin(i|j)[2:])
        a12=a12.rjust(n,'0')
        a12=a12.replace('1','#')
        a12=a12.replace('0',' ')
        answer.append(a12)
    return answer

*rjust( 공백의 수, 공백을 메워줄 문자)