[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค-Lv1] [1์ฐจ] ๋น„๋ฐ€์ง€๋„ / Python

๐Ÿ“š Problem Solving/Programmers

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - [1์ฐจ] ๋น„๋ฐ€์ง€๋„

๋น„๋ฐ€์ง€๋„ ๋„ค์˜ค๋Š” ํ‰์†Œ ํ”„๋กœ๋„๊ฐ€ ๋น„์ƒ๊ธˆ์„ ์ˆจ๊ฒจ๋†“๋Š” ์žฅ์†Œ๋ฅผ ์•Œ๋ ค์ค„ ๋น„๋ฐ€์ง€๋„๋ฅผ ์†์— ๋„ฃ์—ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ด ๋น„๋ฐ€์ง€๋„๋Š” ์ˆซ์ž๋กœ ์•”ํ˜ธํ™”๋˜์–ด ์žˆ์–ด ์œ„์น˜๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•”ํ˜ธ๋ฅผ ํ•ด๋…ํ•ด์•ผ ํ•œ๋‹ค. ๋‹ค

programmers.co.kr

import sys

input = sys.stdin.readline
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))


def solution(n, arr1, arr2):
    answer = []
    for i in range(len(arr1)):
        temp1 = bin(arr1[i] | arr2[i])[2:]
        temp2 = "0" * (n - len(temp1)) + temp1
        temp2 = temp2.replace("0", " ")
        temp2 = temp2.replace("1", "#")
        answer.append(temp2)
    return answer


print(solution(n, arr1, arr2))

 

ํ•ด์„ค

or ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋‘˜ ์ค‘ ํ•˜๋‚˜๊ฐ€ 1์ด๋ฉด 1์ด๊ธฐ ๋•Œ๋ฌธ์— ์ง€๋„๋ฅผ ๊ฒน์ณค์„ ๋•Œ์˜ ๊ฒฐ๊ณผ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

ํ•ด๋‹น ๊ฒฐ๊ณผ๋ฅผ bin์„ ์ด์šฉํ•ด 2์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ์•ž 0์˜ ๊ฐœ์ˆ˜๋Š” n-len(temp1)๋งŒํผ ์ถ”๊ฐ€์‹œํ‚จ๋‹ค.

 

์ด๋ ‡๊ฒŒ ์–ป์€ ๋ฐ์ดํ„ฐ์—์„œ 1์€ '#'์œผ๋กœ, 0์€ ' '์œผ๋กœ replace์‹œํ‚จ ํ›„, answer ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€์‹œํ‚จ๋‹ค.