[Programmers] ๋น„๋ฐ€์ง€๋„

Updated:

๋น„๋ฐ€์ง€๋„

๋น„๋ฐ€์ง€๋„ ๋ฅผ ํด๋ฆญํ•˜๋ฉด ๋ฐ”๋กœ ์ด๋™ํ•œ๋‹ค.

๋‘ ๋ฐฐ์—ด์„ 2์ง„์ˆ˜๋กœ ๋ฐ”๊พผ ๋’ค, or ๊ณ„์‚ฐ์„ ํ†ตํ•ด ๋‚˜์˜จ ๊ฐ’์„ ๊ฐ€์ง€๊ณ 

๊ณต๋ฐฑ๊ณผ ๋ฒฝ์„ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๋ฌธ์ œ์ด๋‹ค.

๋ฌธ์ œ ํ’€์ด ๊ณผ์ •์€ ์‰ฌ์šด๋ฐ ๋˜ ๋Š๋ผ์ง€๋งŒ ์ฝ”๋“œ๋ฅผ ์งœ๊ณ  ๋ณด๋‹ˆ ๋„ˆ๋ฌด C ๊ฐ™์€ ๋Š๋‚Œ์ด ๋‚œ๋‹ค.

def solution(n, arr1, arr2):
	answer = [''for i in range(n)]
	
	bitCal = []
	for i in range(len(arr1)):
		bitCal.append(bin(arr1[i]|arr2[i])[2:])
	print(bitCal)

	index = 0
	for cur in bitCal:
		inputMap = ''
		for i in range(len(cur)):
			if cur[i] == '1':
				inputMap += '#'
			elif cur[i] == '0':
				inputMap += ' '

		if len(inputMap) != n:
			extraSpace = ''
			for i in range(n-len(inputMap)):
				extraSpace += ' '
			inputMap = extraSpace + inputMap
		answer[index] = inputMap
		index += 1

	return answer

์ด๋ ‡๊ฒŒ ํ’€๊ณ  ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ ๋‚ด๊ฐ€ ์ผ์ผ์ด ๋งŒ๋“  ๊ธฐ๋Šฅ์ด

ํŒŒ์ด์ฌ์—์„  ์ด๋ฏธ ์ „๋ถ€ ํ•จ์ˆ˜๋กœ ์กด์žฌํ•˜๋Š” ๊ธฐ๋Šฅ์ด์—ˆ๋‹ค..

๋˜ ๋งŽ์€ ๊ฑธ ๋ฐฐ์›Œ ๊ฐ„๋‹ค..

[Python] String ๊ณผ zip ์‚ฌ์šฉ


Categories:

Updated:

Leave a comment